From e0737c56c1e384e05064a0c6e1ac46979371041b Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Wed, 19 Dec 2018 22:58:32 +0100 Subject: New upstream version 2.0.0+repack --- .../libs/math/example/test_nonfinite_loopback.cpp | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 boost/libs/math/example/test_nonfinite_loopback.cpp (limited to 'boost/libs/math/example/test_nonfinite_loopback.cpp') diff --git a/boost/libs/math/example/test_nonfinite_loopback.cpp b/boost/libs/math/example/test_nonfinite_loopback.cpp new file mode 100644 index 00000000..c7b8e420 --- /dev/null +++ b/boost/libs/math/example/test_nonfinite_loopback.cpp @@ -0,0 +1,97 @@ +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +// Copyright (c) 2006 Johan Rade +// Copyright (c) 2011 Paul A. Bristow + +/*! +\file +\brief Basic tests of native nonfinite loopback. + +\detail Basic loopback test outputs using the platforms built-in facets +and reads back in, and checks if loopback OK. + +Using MSVC this doesn't work OK: +input produces just "1" instead of "1.#QNAN", 1.#SNAN" or 1.#IND"! + +*/ + +#include +using std::cout; +using std::endl; +#include +using std::locale; +#include +using std::string; +#include + using std::stringstream; +#include +using std::numeric_limits; + +int main() +{ + locale default_locale; // Current global locale. + // Try to use the default locale first. + // On MSVC this doesn't work. + + { // Try infinity. + stringstream ss; // Both input and output. + ss.imbue(default_locale); // Redundant, of course. + string infs; + if(numeric_limits::has_infinity) + { // Make sure infinity is specialised for type double. + double inf = numeric_limits::infinity(); + ss << inf; // Output infinity. + infs = ss.str(); // + } + else + { // Need to provide a suitable string for infinity. + infs = "1.#INF"; // Might suit MSVC? + ss << infs; + } + double r; + ss >> r; // Read back in. + + cout << "infinity output was " << infs << endl; // "1.#INF" + cout << "infinity input was " << r << endl; // "1" + } + + { // Try Quiet NaN + stringstream ss; // Both input and output. + ss.imbue(default_locale); // Redundant, of course. + string infs; + if(numeric_limits::has_quiet_NaN) + { // Make sure quiet NaN is specialised for type double. + double qnan = numeric_limits::quiet_NaN(); + ss << qnan; // Output quiet_NaN. + infs = ss.str(); // + } + else + { // Need to provide a suitable string for quiet_NAN. + infs = "1.#QNAN"; + ss << infs; + } + double r; + ss >> r; // Read back in. + + cout << "quiet_NaN output was " << infs << endl; // "1.#QNAN" + cout << "quiet_NaN input was " << r << endl; // "1#" + } + + +} // int main() + +/* + +Output (MSVC Version 10.0): + + + infinity output was 1.#INF + infinity input was 1 + quiet_NaN output was 1.#QNAN + quiet_NaN input was 1 + + +*/ + -- cgit v1.2.3