Ticket #12039 (closed Bugs: fixed)
cpp_bin_float convert_to<double>() rounding mistake
|Reported by:||Michael Shatz <shatz@…>||Owned by:||johnmaddock|
|Milestone:||To Be Determined||Component:||multiprecision|
There are cases where cpp_bin_float convert_to<double>() does not produce the nearest 'double' result. It happens when the source argument differs form the middle point between two double-precision values in 65th bit or further. I didn't look at boost source code, but pretty sure that the mistakes occurs due to double rounding. I.e. instead of direct rounding to 53-bit precision of 'double' the number is initially converted to 64-bit 'long double' and then converted from 'long double' to 'double'.
In particular, on Microsoft compilers 'long double' and 'double' refer to the same type and the mistake does not happen. But on the same machine/OS with gcc compiler the mistake does happen.
Below attached a simple test case that prints 'good' on platforms without bug and prints bad on platforms with bug.
- Owner set to johnmaddock
- Component changed from None to multiprecision
- Status changed from new to closed
- Resolution set to fixed