// Test SPARC 128 bit double extended (quad) format // long double smallest intervals of math constant pi // Paul A Bristow, Oct 2002 #include #include // for numeric limits. using std::cout; using std::endl; // Exactly representable in 128 bit SPARC & VAX H double extended format smallest interval values of pi. static const long double pi_l = 3.141592653589793238462643383279502797479068098137295573004504331874296718662975536062731407582759857177734375L; static const long double pi = 3.1415926535897932384626433832795028841971694007530292958410328557937120280044899746529304611532080295833741639955L; static const long double pi_u = 3.141592653589793238462643383279503182665056975584466184200092848859760426283305179140370455570518970489501953125L; void check(long double l,long double m, long double h); int main() { int long_double_significant_digits = 2 + 113 * 30101/100000; // 36 cout << "long double_significant_digits " << long_double_significant_digits << endl; cout.precision(long_double_significant_digits); // Show all possibly significant. cout << "std::numeric_limits::digits = " << std::numeric_limits::digits << endl; // Expect 112 + 1 implicit = 113 significand or mantissa bits. cout << "pi_l = " << pi_l << endl; cout << "pi = " << pi << endl; cout << "pi_u = " << pi_u << endl; check(pi_l, pi, pi_u); // Expect middle is either upper or lower limit, but not both. // and no warnings! return 0; } // int main() void check(long double l,long double m, long double h) { // Check that 'middle' long double value is either upper or lower interval, or both. bool is_lower = static_cast(l == m); bool is_upper = static_cast(h == m); if (is_lower && is_upper) { // Both. cout << "lower, middle & upper are same." << endl; } else { // Different, but expect upper or lower to be same as middle. if (is_lower) { cout << "middle is lower limit." << endl; } if (is_upper) { cout << "middle is upper limit." << endl; } if (!(is_lower) && !(is_upper)) { // Neither! std::cerr << "WARNING : middle is neither lower nor upper limit!" << std::endl; if (m > h) { std::cerr << "WARNING : middle > upper limit!" << std::endl; } if (m < l) { std::cerr << "WARNING : middle < lower limit!" << std::endl; } } long double lp = l + h; // lower + upper long double two = long double(2.L); if ((lp < two * h) && (lp > two * l)) { std::cerr << "WARNING : more precise interval possible!" << std::endl; } } } // Check /* MSVC 7.0 long double_significant_digits 36 std::numeric_limits::digits = 53 <<<<< SPARC should be 113 pi_l = 3.1415926535897931 pi = 3.1415926535897931 pi_u = 3.1415926535897931 lower, middle & upper are same.<<<<< SPARC should be different. Press any key to continue */