Opened 8 years ago

Last modified 8 years ago

#11178 new Bugs

cpp_dec_float calculation bug

Reported by: nxjiang1@… Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.57.0 Severity: Problem
Keywords: Cc: e_float@…

Description

#include <iostream>

#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace boost::multiprecision; using namespace std;

int main(int argc, char *argv[]) {

cpp_dec_float_100 p("4.5"); cpp_dec_float_100 a("7.2");

cpp_dec_float_100 r = p / a;("0.625"); cout << r.str() << endl;

if (r == cpp_dec_float_100("0.625")) cout << "HOHO" << endl; cout << r.str(2, ios_base::fixed) << endl;

r *= 100; cout << r.str(2, ios_base::fixed) << endl; r = round(r); cout << r.str(2, ios_base::fixed) << endl; r /= 100;

cout << r.str(2, ios_base::fixed) << endl;

return 0;

}

Change History (1)

comment:1 by John Maddock, 8 years ago

Cc: e_float@… added

I'm CC'ing Chris into this as he would know more, but I suspect this is expected behaviour as the type does not perform rounding on arithmetic operations, consequently the division produces an inexact result where an exact one should be possible. Chris?

Note: See TracTickets for help on using tickets.