]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/nonfinite_legacy.cpp
1 // nonfinite_legacy.cpp
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Copyright (c) 2006 Johan Rade
8 // Copyright (c) 2011 Paul A. Bristow
12 \brief Basic tests of nonfinite loopback with output and input facet.
14 \detail Basic loopback test outputs using the so-called 'legacy' facets,
15 "1.#INF" and "1.#QNAN".
17 and reads back in using nonfinite input 'legacy' facet, and
18 (if possible) checks if loopback OK.
22 #include <boost/math/special_functions/nonfinite_num_facets.hpp>
23 using boost::math::nonfinite_num_put
;
24 using boost::math::nonfinite_num_get
;
26 using boost::math::legacy
;
40 using std::stringstream
;
42 using std::numeric_limits
;
48 // Create a new locale with both the nonfinite facets.
49 std::locale
new_locale(std::locale(std::locale(),
50 new boost::math::nonfinite_num_put
<char>),
51 new boost::math::nonfinite_num_get
<char>);
56 double inf
= numeric_limits
<double>::infinity();
57 ss
<< inf
; // Write out.
59 ss
>> r
; // Read back in.
61 cout
<< "infinity output was " << inf
<< endl
;
62 cout
<< "infinity input was " << r
<< endl
;
64 BOOST_ASSERT(inf
== r
);
70 double nan
= numeric_limits
<double>::quiet_NaN();
71 ss
<< nan
; // Write out.
73 ss
>> v
; // Read back in.
75 cout
<< "NaN output was " << nan
<< endl
;
76 cout
<< "NaN input was " << v
<< endl
;
78 // BOOST_ASSERT(nan == v); // Always fails because NaN == NaN fails!
79 // BOOST_ASSERT(nan == numeric_limits<double>::quiet_NaN()); asserts!
88 infinity output was 1.#INF
89 infinity input was 1.#INF
90 NaN output was 1.#QNAN