Ticket #12039: convert_test.cpp

File convert_test.cpp, 516 bytes (added by Michael Shatz <shatz@…>, 7 years ago)

convert_to<double>() bug reproducer

Line 
1#include <stdio.h>
2#include <boost/multiprecision/cpp_bin_float.hpp>
3
4
5typedef boost::multiprecision::number<boost::multiprecision::backends::cpp_bin_float<256> > ext_float_t;
6
7int main(int, char**) {
8 ext_float_t x = 5e15;
9 x += 0.5;
10 ext_float_t x1 = x + 255.0/(1<<20); // + 2^-12 - eps
11 ext_float_t x2 = x + 257.0/(1<<20); // + 2^-12 + eps
12 double d1 = x1.convert_to<double>();
13 double d2 = x2.convert_to<double>();
14 printf("%.1f\n%.1f\n%s\n", d1, d2, d1==d2 ? "good" : "bad");
15 return 0;
16}