a bug in DIV
yunyng opened this issue · 1 comments
Details
a bug in (1453302010683093905187502545111768308832134376934/(-10531))
the result is -1380022880000293790256148755589380714920912959
but the right is -138002280000293790256148755589380714920912959
in function "std::tuple<BigInt, BigInt> divide(const BigInt& dividend, const BigInt& divisor) "
"while (temp < dividend) " may change to "while (temp <= dividend) "
System info
- OS: Red Hat 4.8.5-4
- Compiler: gcc version 4.8.5
Withot changing the code for divide
I added the following to the "Division of big numbers" test case in test/operators/binary_arithmetic.cpp
and ran make test
and got the expected result:
num1 = "1453302010683093905187502545111768308832134376934";
num2 = -10531;
REQUIRE(num1 / num2 == "-138002280000293790256148755589380714920912959");
Test project /home/faheel/Projects/Personal/BigInt/build
Start 1: ConstructorsTest
1/11 Test #1: ConstructorsTest .................... Passed 0.00 sec
Start 2: FunctionsConversionTest
2/11 Test #2: FunctionsConversionTest ............. Passed 0.00 sec
Start 3: FunctionsMathTest
3/11 Test #3: FunctionsMathTest ................... Passed 0.60 sec
Start 4: FunctionsRandomTest
4/11 Test #4: FunctionsRandomTest ................. Passed 0.07 sec
Start 5: OperatorsArithmeticAssignmentTest
5/11 Test #5: OperatorsArithmeticAssignmentTest ... Passed 0.01 sec
Start 6: OperatorsAssignmentTest
6/11 Test #6: OperatorsAssignmentTest ............. Passed 0.00 sec
Start 7: OperatorsBinaryArithmeticTest
7/11 Test #7: OperatorsBinaryArithmeticTest ....... Passed 0.14 sec
Start 8: OperatorsIncrementDecrementTest
8/11 Test #8: OperatorsIncrementDecrementTest ..... Passed 0.00 sec
Start 9: OperatorsIOStreamTest
9/11 Test #9: OperatorsIOStreamTest ............... Passed 0.00 sec
Start 10: OperatorsRelationalTest
10/11 Test #10: OperatorsRelationalTest ............. Passed 0.00 sec
Start 11: OperatorsUnaryArithmeticTest
11/11 Test #11: OperatorsUnaryArithmeticTest ........ Passed 0.00 sec
100% tests passed, 0 tests failed out of 11
Total Test time (real) = 0.86 sec
Can you try the same and see whether the tests pass? Also, can you check whether you really got the wrong result that you mentioned (-1380022880000293790256148755589380714920912959)?