stepthom / math-fun

Just testing out some fun with mathematics.
2 stars 2 forks source link

Use BigInt and BigDecimal to avoid potential overflow/underflow issues in Fraction #55

Closed stepthom closed 10 years ago

stepthom commented 10 years ago

(Split from #47. See discussion there for more background.)

Many functions in the Fraction class have the ability to overflow or underflow. Modify the package to use BigInt instead of integers/longs and BigDecimal instead of floats/doubles.

Please add some tests that test cases that would cause overflow to be sure they are handled correctly.

cconvey commented 10 years ago

I implemented BigInteger and BigDecimal in the Fraction class, and added a few new testcases to confirm that the numerator and denominator can handle values larger than Java's 'int' type allows.

Java seems to provide nothing like a pow(...) function for the BigDecimal class. Therefore it's hard to propagate the use of BigDecimal into the operations such as Term.evaluate(...), MathFunction.evaluate(...) and MathFunction.solve(...), where we would have liked to be able to use the extended precision provided by BigDecimal. (This would have been fairly simple if we only allowed our Terms to have integer exponents, but we allow fractional exponents as well.)