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 --- boost/libs/math/example/nonfinite_loopback_ok.cpp | 89 +++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 boost/libs/math/example/nonfinite_loopback_ok.cpp (limited to 'boost/libs/math/example/nonfinite_loopback_ok.cpp') diff --git a/boost/libs/math/example/nonfinite_loopback_ok.cpp b/boost/libs/math/example/nonfinite_loopback_ok.cpp new file mode 100644 index 00000000..adeea76c --- /dev/null +++ b/boost/libs/math/example/nonfinite_loopback_ok.cpp @@ -0,0 +1,89 @@ +// 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 nonfinite loopback. + +\detail Basic loopback test outputs using nonfinite facets +(output and input) and reads back in, and checks if loopback OK. + +Expected to work portably on all platforms. + +*/ + +#ifdef _MSC_VER +# pragma warning(disable : 4702) +# pragma warning(disable : 4127) // conditional expression is constant. +#endif + +#include +using boost::math::nonfinite_num_get; +using boost::math::nonfinite_num_put; + +#include +using std::cout; +using std::endl; + +#include +using std::locale; + +#include +using std::stringstream; +#include +using std::numeric_limits; + +#include + +int main() +{ + + if((std::numeric_limits::has_infinity == false) || (std::numeric_limits::infinity() == 0)) + { + std::cout << "Infinity not supported on this platform." << std::endl; + return 0; + } + + if((std::numeric_limits::has_quiet_NaN == false) || (std::numeric_limits::quiet_NaN() == 0)) + { + std::cout << "NaN not supported on this platform." << std::endl; + return 0; + } + //locale old_locale; // Current global locale. + // Create tmp_locale and store the output nonfinite_num_put facet in it. + //locale tmp_locale(old_locale, new nonfinite_num_put); + // Create new_locale and store the input nonfinite_num_get facet in it. + //locale new_locale(tmp_locale, new nonfinite_num_get); + // Can only add one facet at a time, hence need a tmp_locale. + // Unless we write: + + std::locale new_locale(std::locale(std::locale(std::locale(), + new boost::math::nonfinite_num_put), + new boost::math::nonfinite_num_get)); + + stringstream ss; // Both input and output, so need both get and put facets. + + ss.imbue(new_locale); + + double inf = numeric_limits::infinity(); + ss << inf; // Write out. + double r; + ss >> r; // Read back in. + + assert(inf == r); // OK MSVC <= 10.0! + +} // int main() + +/* + +Output: + +nonfinite_loopback_ok.vcxproj -> J:\Cpp\fp_facet\fp_facet\Debug\nonfinite_loopback_ok.exe + +*/ + + -- cgit v1.2.3