Ticket #8065: MPRoundingBug.cpp

File MPRoundingBug.cpp, 955 bytes (added by Matthias Wagner <MWagner@…>, 10 years ago)
Line 
1#include <iostream>
2#include <Windows.h>
3#include <boost/math/special_functions/round.hpp>
4#include <boost/multiprecision/cpp_dec_float.hpp>
5
6namespace mp = boost::multiprecision;
7
8template<int N>
9void roundTest()
10{
11 typedef mp::number<mp::cpp_dec_float<N>, mp::et_off> decimal;
12
13 const decimal origDigs(1.0);
14 const decimal scale = pow(decimal(10), N);
15 decimal digs = origDigs * scale;
16 digs = boost::math::round(digs );
17 digs = digs / scale;
18
19 std::string result = digs.str();
20 if (result != origDigs.str())
21 {
22 std::cout << "roundTest failed for N = " << N << ": " << result << std::endl;
23 }
24}
25
26template<int N>
27struct roundTester
28{
29 static void test ()
30 {
31 roundTest<N>();
32 roundTester<N-1>::test();
33 }
34};
35
36template<>
37struct roundTester<0>
38{
39 static void test ()
40 {
41 roundTest<0>();
42 }
43};
44
45int main(int argc, char* argv[])
46{
47 roundTester<60>::test();
48 return 0;
49}
50