Opened 5 years ago
Closed 5 years ago
#13347 closed Bugs (duplicate)
4.666662/0.666666 is not equal to 7
Reported by: | anonymous | Owned by: | John Maddock |
---|---|---|---|
Milestone: | To Be Determined | Component: | multiprecision |
Version: | Boost 1.65.0 | Severity: | Problem |
Keywords: | Cc: |
Description
I expect to get 7 when I divide 4.666662/0.666666 using boost::multiprecision::cpp_dec_float_50 but I get false when I compare the result with 7. Here is the code:
#include <boost/multiprecision/cpp_dec_float.hpp> #include <iostream> int main() { using boost::multiprecision::cpp_dec_float_50; cpp_dec_float_50 left("4.666662"), right("0.666666"); cpp_dec_float_50 div_res = left/right, correct_div_res("7"); std::cout << std::boolalpha << (div_res == correct_div_res) << std::endl; }
Attachments (1)
Change History (6)
by , 5 years ago
comment:1 by , 5 years ago
comment:2 by , 5 years ago
Building with --std=c++11 gives the same wrong result:
$ clang++-4.0 -g -I ../include --std=c++11 main.cpp $ ./a.out false
comment:4 by , 5 years ago
We know: cpp_dec_float does not perform rounding, and has internal guard digits, both of which will cause this behaviour.
Note:
See TracTickets
for help on using tickets.
I build the test with clang 4.0 on Ubuntu 16.04: