]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/test_cstdfloat.cpp
1 // Copyright Christopher Kormanyos 2014.
2 // Copyright John Maddock 2014.
3 // Copyright Paul A. Bristow 2014.
5 // Use, modification and distribution are subject to the
6 // Boost Software License, Version 1.0. (See accompanying file
7 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
16 #include <boost/math/cstdfloat/cstdfloat_types.hpp>
19 # pragma warning(disable : 4127) // conditional expression is constant.
20 # pragma warning(disable : 4512) // assignment operator could not be generated.
21 # pragma warning(disable : 4996) // use -D_SCL_SECURE_NO_WARNINGS.
24 #define BOOST_TEST_MAIN
25 #include <boost/test/unit_test.hpp> // Boost.Test
26 #include <boost/test/floating_point_comparison.hpp>
32 // This file tests the implementation of floating-point typedefs having
33 // specified widths, as implemented in <boost/cstdfloat.hpp> and described
34 // in N3626 (proposed for C++14).
36 // For more information on <boost/cstdfloat.hpp> and the corresponding
37 // proposal of "Floating-Point Typedefs Having Specified Widths",
38 // see: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3626.pdf
42 // Perform sanity checks on boost::float16_t, boost::float32_t,
43 // boost::float64_t, boost::float80_t, and boost::float128_t when
44 // these types are available. In the sanity checks, we verify the
45 // formal behavior of the types and the macros for creating literal
46 // floating-point constants.
48 // An extended check is included for boost::float128_t. This checks
49 // the functionality of <cmath>, I/O stream operations, and <complex>
50 // functions for boost::float128_t.
52 #define TEST_CSTDFLOAT_SANITY_CHECK(the_digits) \
53 void sanity_check_##the_digits##_func() \
55 typedef boost::float##the_digits##_t float_type; \
57 BOOST_CONSTEXPR_OR_CONST int my_digits10 = std::numeric_limits<float_type>::digits10; \
60 BOOST_CONSTEXPR_OR_CONST float_type x = \
61 BOOST_FLOAT##the_digits##_C(0.33333333333333333333333333333333333333333); \
62 std::stringstream ss; \
63 ss << std::setprecision(my_digits10 - 1) \
65 std::string str = "0."; \
66 str += std::string(std::string::size_type(my_digits10 - 1), char('3')); \
67 BOOST_CHECK_EQUAL( ss.str(), str ); \
70 BOOST_CONSTEXPR_OR_CONST float_type x = \
71 BOOST_FLOAT##the_digits##_C(0.66666666666666666666666666666666666666666); \
72 std::stringstream ss; \
73 ss << std::setprecision(my_digits10 - 1) \
75 std::string str = "0."; \
76 str += std::string(std::string::size_type(my_digits10 - 2), char('6')); \
78 BOOST_CHECK_EQUAL( ss.str(), str ); \
81 const float_type x = BOOST_FLOAT##the_digits##_C(1.0) / test_cstdfloat::zero; \
82 const bool the_inf_test = ( std::numeric_limits<float_type>::has_infinity \
83 && (x == std::numeric_limits<float_type>::infinity())); \
84 BOOST_CHECK_EQUAL( the_inf_test, true ); \
88 const float_type x = sqrt(float_type(test_cstdfloat::minus_one)); \
89 const bool the_nan_test = ( std::numeric_limits<float_type>::has_quiet_NaN \
91 BOOST_CHECK_EQUAL( the_nan_test, true ); \
94 const bool the_lim_test = \
95 (std::numeric_limits<boost::floatmax_t>::digits >= std::numeric_limits<float_type>::digits); \
96 BOOST_CHECK_EQUAL( the_lim_test, true ); \
100 namespace test_cstdfloat
105 #if defined(BOOST_FLOATMAX_C)
106 BOOST_CONSTEXPR_OR_CONST
int has_floatmax_t
= 1;
108 BOOST_CONSTEXPR_OR_CONST
int has_floatmax_t
= 0;
111 #if defined(BOOST_FLOAT16_C)
112 TEST_CSTDFLOAT_SANITY_CHECK(16)
115 #if defined(BOOST_FLOAT32_C)
116 TEST_CSTDFLOAT_SANITY_CHECK(32)
119 #if defined(BOOST_FLOAT64_C)
120 TEST_CSTDFLOAT_SANITY_CHECK(64)
123 #if defined(BOOST_FLOAT80_C)
124 TEST_CSTDFLOAT_SANITY_CHECK(80)
127 #if defined(BOOST_FLOAT128_C)
128 TEST_CSTDFLOAT_SANITY_CHECK(128)
130 void extend_check_128_func()
133 #endif // defined (BOOST_FLOAT128_C)
136 BOOST_AUTO_TEST_CASE(test_main
)
138 test_cstdfloat::zero
= 0;
139 test_cstdfloat::minus_one
= -1;
141 // Perform basic sanity checks that verify both the existence of the proper
142 // floating-point literal macros as well as the correct digit handling
143 // for a given floating-point typedef having specified width.
145 BOOST_CHECK_EQUAL( test_cstdfloat::has_floatmax_t
, 1 );
147 #if defined(BOOST_FLOAT16_C)
148 test_cstdfloat::sanity_check_16_func();
151 #if defined(BOOST_FLOAT32_C)
152 test_cstdfloat::sanity_check_32_func();
155 #if defined(BOOST_FLOAT64_C)
156 test_cstdfloat::sanity_check_64_func();
159 #if defined(BOOST_FLOAT80_C)
160 test_cstdfloat::sanity_check_80_func();
163 #if defined(BOOST_FLOAT128_C)
164 test_cstdfloat::sanity_check_128_func();
166 // Perform an extended check of boost::float128_t including
167 // a variety of functions from the C++ standard library.
168 test_cstdfloat::extend_check_128_func();
169 #endif // defined (BOOST_FLOAT128_C)