1
Vote

BigInteger divison modifies the divisor

description

I discovered an error in attempting to create a BigRational from a double without resorting to string parsing (extract the mantissa and exponent bits directly). When the BigInteger numerator and denominator values are large enough, the division during Simplify modifies the GCD.

The following will fail every time:
BigInteger a = BigInteger.Parse("4503599627370496");
BigInteger b = BigInteger.Parse("6755399441055744");
BigRational c = new BigRational(a, b);
string d = c.ToDecimalString(10);
See the screenshot where the GDC is modified. The modification is made at BigInteger:2558.

file attachments

comments

Draco18s wrote Mar 4 at 6:15 PM

Also, line 1011 of BigRational should be
if (y == 0)
Because otherwise if you switch the numerator and demominator of the code snip above, d will be "3" not the correct value of "1.5"