AdamWhiteHat / BigRational

Arbitrary precision rational number class
MIT License
24 stars 2 forks source link

BUG: Arithmetic bug with negative numbers #10

Closed stewienj closed 4 years ago

stewienj commented 4 years ago

Description There's an arithmetic bug with negative numbers, e.g. add -7 and -6 together and halve to find the mid point. I get -5.5, not the expected -6.5.

Steps To Reproduce

[TestMethod, TestCategory("Arithmetic")]
public void TestMidPoint()
{
    var low = (BigRational)(-7);
    var high = (BigRational)(-6);

    // Take the mid point of the above 2 numbers
    var mid = (low + high) / (BigRational)2;

    Assert.IsTrue(mid > low);
    Assert.IsTrue(mid < high);
}

Took me a while to realize I wasn't going crazy.

AdamWhiteHat commented 4 years ago

This should be fixed now..