|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77516 - trunk/libs/math/test
From: john_at_[hidden]
Date: 2012-03-24 15:30:53
Author: johnmaddock
Date: 2012-03-24 15:30:52 EDT (Sat, 24 Mar 2012)
New Revision: 77516
URL: http://svn.boost.org/trac/boost/changeset/77516
Log:
Update test to determine heuristically how the std lib formats zeros.
Text files modified:
trunk/libs/math/test/test_signed_zero.cpp | 42 +++++++++++++++++++++++++++++++--------
1 files changed, 33 insertions(+), 9 deletions(-)
Modified: trunk/libs/math/test/test_signed_zero.cpp
==============================================================================
--- trunk/libs/math/test/test_signed_zero.cpp (original)
+++ trunk/libs/math/test/test_signed_zero.cpp 2012-03-24 15:30:52 EDT (Sat, 24 Mar 2012)
@@ -132,6 +132,21 @@
BOOST_AUTO_TEST_CASE(misc_output_tests)
{ // Tests of output using a variety of output options.
+ //
+ // STD libraries don't all format zeros the same,
+ // so figure out what the library-specific formatting is
+ // and then make sure that our facet produces the same...
+ //
+ bool precision_after = false; // Prints N digits after the point rather than N digits total
+ bool triple_exponent = false; // Has 3 digits in the exponent rather than 2.
+ std::stringstream ss;
+ ss << std::showpoint << std::setprecision(6) << 0.0;
+ if(ss.str().size() == 8)
+ precision_after = true;
+ ss.str("");
+ ss << std::scientific << 0.0;
+ triple_exponent = ss.str().size() - ss.str().find_first_of('e') == 5;
+
// Positive zero.
@@ -145,14 +160,17 @@
CHECKOUT(std::setw(4) << std::internal << std::setfill('*') << 0., "***0"); // left adjust sign and right adjust value.
CHECKOUT(std::showpos << std::setw(4) << std::internal << std::setfill('*') << 0., "+**0"); // left adjust sign and right adjust value.
-#if defined(_CPPLIB_VER) && (_CPPLIB_VER >= 306)
+ if(precision_after)
+ {
// BOOST_STDLIB == ("Dinkumware standard library version" BOOST_STRINGIZE(_CPPLIB_VER)) )
CHECKOUT(std::showpoint << 0., "0.000000"); // std::setprecision(6)
CHECKOUT(std::setprecision(2) << std::showpoint << 0., "0.00");
-#else
+ }
+ else
+ {
CHECKOUT(std::showpoint << 0., "0.00000"); // std::setprecision(6)
CHECKOUT(std::setprecision(2) << std::showpoint << 0., "0.0");
-#endif
+ }
CHECKOUT(std::fixed << std::setw(5) << std::setfill('0') << std::setprecision(2) << 0., "00.00");
CHECKOUT(std::fixed << std::setw(6) << std::setfill('0') << std::setprecision(2) << 0., "000.00");
CHECKOUT(std::fixed << std::setw(6) << std::setfill('0') << std::setprecision(3) << 0., "00.000");
@@ -161,11 +179,14 @@
CHECKOUT(std::showpos << 0., "+0");
CHECKOUT(std::showpos << std::fixed << std::setw(6) << std::setfill('*') << std::setprecision(2) << std::left << 0.0, "+0.00*");
-#if defined(BOOST_MSVC) && defined(_CPPLIB_VER)
+ if(triple_exponent)
+ {
CHECKOUT(std::scientific << std::showpoint << std::setw(10) << std::setfill('*') << std::setprecision(1) << std::left << 0., "0.0e+000**");
-#else
+ }
+ else
+ {
CHECKOUT(std::scientific << std::showpoint << std::setw(10) << std::setfill('*') << std::setprecision(1) << std::left << 0., "0.0e+00***");
-#endif
+ }
CHECKOUT(std::fixed << std::showpoint << std::setw(6) << std::setfill('*') << std::setprecision(3) << std::left << 0., "0.000*");
double nz = (changesign)(static_cast<double>(0)); // negative signed zero.
@@ -186,15 +207,18 @@
CHECKOUT(std::fixed << std::setw(6) << std::setfill('*') << std::setprecision(3) << 0., "*0.000");
CHECKOUT(std::fixed << std::setw(6) << std::setfill('*') << std::setprecision(2) << std::left << 0.0, "0.00**");
CHECKOUT(std::setprecision(2) << nz, "-0"); // No showpoint, so no decimal point nor trailing zeros.
-#if defined(BOOST_MSVC) && defined(_CPPLIB_VER)
+ if(precision_after)
+ {
CHECKOUT(std::setprecision(2) << std::showpoint << nz, "-0.00"); // or "-0.0"
CHECKOUT(std::scientific << std::showpoint << std::setw(10) << std::setfill('*') << std::setprecision(1) << std::left << nz, "-0.0e+000*"); // -0.0e+00**
CHECKOUT(std::setw(1) << std::setprecision(3) << std::showpoint << nz, "-0.000"); // Not enough width for precision overflows width. or "-0.00"
-#else
+ }
+ else
+ {
CHECKOUT(std::setprecision(2) << std::showpoint << nz, "-0.0"); // or "-0.00"
CHECKOUT(std::scientific << std::showpoint << std::setw(10) << std::setfill('*') << std::setprecision(1) << std::left << nz, "-0.0e+00**"); // -0.0e+000*
CHECKOUT(std::setw(1) << std::setprecision(3) << std::showpoint << nz, "-0.00"); // Not enough width for precision overflows width. or "-0.000"
-#endif
+ }
CHECKOUT(std::fixed << std::showpoint << std::setw(6) << std::setfill('*') << std::setprecision(3) << std::left << 0., "0.000*");
// Non zero values.
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk