I'm developing a Big Integer class(didactic purpose) and I have been using Ruby to generate test cases. My class fails in the following test:
a = -48197174570431531987668852939807674377435188974148779416366905274642031729688518691
b = 4322669160730708444058642850762359547515258361061655693150034467061
a / b = -11149864303351921 # Ruby answer
I could not find the bug in my code so I tried to verify the result with other tools and surprise :o.
GMP, Java BigInteger and my class coincides with this results:
11149864303351920
-11149864303351920
But Ruby and Python coincides with this:
-11149864303351921
11149864303351920
Can somebody explain why this behavior?, Please.
When the arguments to integer division are not both positive, a decision must be made for rounding of the quotient and sign of the remainder. GMP supports floor division (f_div...), ceiling division (c_div...), and truncating division (t_div...).
Using gmpy2 to access GMP via Python,