@@ -49,6 +49,39 @@ namespace sw { namespace universal {
49
49
reportConversionError (reportRoundTrip<rb64, Real>(1 , 5 ));
50
50
}
51
51
52
+ template <typename Real>
53
+ void roundingError (uint64_t a, uint64_t b) {
54
+ constexpr unsigned nbits = sizeof (Real) * 8 ;
55
+ blockbinary<nbits> numerator{static_cast <int64_t >(a)}, denominator{ static_cast <int64_t >(b)};
56
+ int WIDTH = sizeof (Real)*8 + 5 ;
57
+
58
+ auto precision = std::cout.precision ();
59
+ std::cout << std::setprecision (std::numeric_limits<Real>::max_digits10);
60
+
61
+ for (unsigned i = 0 ; i < ieee754_parameter<Real>::fbits+1 ; ++i) {
62
+ double v = double (numerator) / double (denominator);
63
+ std::cout << std::setw (WIDTH) << to_binary (numerator) << std::setw (WIDTH) << to_binary (denominator) << " : " << v << ' \n ' ;
64
+
65
+ numerator >>= 1 ;
66
+ denominator >>= 1 ;
67
+ }
68
+
69
+ std::cout << std::setprecision (precision);
70
+ }
71
+
72
+ template <typename Real>
73
+ void scaleRoundingError (Real fp) {
74
+ fp = Real (0.2 );
75
+ bool s;
76
+ uint64_t e, f, bits;
77
+ extractFields (fp, s, e, f, bits);
78
+ uint64_t a = f | ieee754_parameter<Real>::hmask;
79
+ uint64_t b = ieee754_parameter<Real>::hmask;
80
+ b <<= 3 ; // associated with the ratio that yields 0.2
81
+
82
+ roundingError<Real>(a, b);
83
+
84
+ }
52
85
} }
53
86
54
87
// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
86
119
Experiment<float >();
87
120
Experiment<double >();
88
121
122
+ scaleRoundingError<float >(0 .2f );
123
+ scaleRoundingError<double >(0.2 );
124
+
89
125
ReportTestSuiteResults (test_suite, nrOfFailedTestCases);
90
126
return EXIT_SUCCESS;
91
127
#else
0 commit comments