1 | #include <iostream>
|
---|
2 | #include <Windows.h>
|
---|
3 | #include <boost/math/special_functions/round.hpp>
|
---|
4 | #include <boost/multiprecision/cpp_dec_float.hpp>
|
---|
5 |
|
---|
6 | namespace mp = boost::multiprecision;
|
---|
7 |
|
---|
8 | template<int N>
|
---|
9 | void 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 |
|
---|
26 | template<int N>
|
---|
27 | struct roundTester
|
---|
28 | {
|
---|
29 | static void test ()
|
---|
30 | {
|
---|
31 | roundTest<N>();
|
---|
32 | roundTester<N-1>::test();
|
---|
33 | }
|
---|
34 | };
|
---|
35 |
|
---|
36 | template<>
|
---|
37 | struct roundTester<0>
|
---|
38 | {
|
---|
39 | static void test ()
|
---|
40 | {
|
---|
41 | roundTest<0>();
|
---|
42 | }
|
---|
43 | };
|
---|
44 |
|
---|
45 | int main(int argc, char* argv[])
|
---|
46 | {
|
---|
47 | roundTester<60>::test();
|
---|
48 | return 0;
|
---|
49 | }
|
---|
50 |
|
---|