]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/core/test/cmath_test.cpp
1 // Test for boost/core/cmath.hpp
3 // Copyright 2020 Peter Dimov
4 // Distributed under the Boost Software License, Version 1.0.
5 // https://www.boost.org/LICENSE_1_0.txt
7 #include <boost/core/cmath.hpp>
8 #include <boost/core/lightweight_test.hpp>
9 #include <boost/config.hpp>
10 #include <boost/config/workaround.hpp>
14 template<class T
> void test_positive_normal( T x
)
16 BOOST_TEST( boost::core::isfinite( x
) );
17 BOOST_TEST( !boost::core::isinf( x
) );
18 BOOST_TEST( !boost::core::isnan( x
) );
19 BOOST_TEST( boost::core::isnormal( x
) );
21 BOOST_TEST_EQ( boost::core::fpclassify( x
), boost::core::fp_normal
);
23 BOOST_TEST( !boost::core::signbit( x
) );
25 BOOST_TEST_EQ( boost::core::copysign( T(+2), x
), T(+2) );
26 BOOST_TEST_EQ( boost::core::copysign( T(-2), x
), T(+2) );
29 template<class T
> void test_negative_normal( T x
)
31 BOOST_TEST( boost::core::isfinite( x
) );
32 BOOST_TEST( !boost::core::isinf( x
) );
33 BOOST_TEST( !boost::core::isnan( x
) );
34 BOOST_TEST( boost::core::isnormal( x
) );
36 BOOST_TEST_EQ( boost::core::fpclassify( x
), boost::core::fp_normal
);
38 BOOST_TEST( boost::core::signbit( x
) );
40 BOOST_TEST_EQ( boost::core::copysign( T(+2), x
), T(-2) );
41 BOOST_TEST_EQ( boost::core::copysign( T(-2), x
), T(-2) );
44 template<class T
> void test_positive_zero( T x
)
46 BOOST_TEST( boost::core::isfinite( x
) );
47 BOOST_TEST( !boost::core::isinf( x
) );
48 BOOST_TEST( !boost::core::isnan( x
) );
49 BOOST_TEST( !boost::core::isnormal( x
) );
51 BOOST_TEST_EQ( boost::core::fpclassify( x
), boost::core::fp_zero
);
53 BOOST_TEST( !boost::core::signbit( x
) );
55 BOOST_TEST_EQ( boost::core::copysign( T(+2), x
), T(+2) );
56 BOOST_TEST_EQ( boost::core::copysign( T(-2), x
), T(+2) );
59 template<class T
> void test_negative_zero( T x
)
61 BOOST_TEST( boost::core::isfinite( x
) );
62 BOOST_TEST( !boost::core::isinf( x
) );
63 BOOST_TEST( !boost::core::isnan( x
) );
64 BOOST_TEST( !boost::core::isnormal( x
) );
66 BOOST_TEST_EQ( boost::core::fpclassify( x
), boost::core::fp_zero
);
68 #if defined(BOOST_CORE_USE_GENERIC_CMATH) && BOOST_WORKAROUND(BOOST_GCC, < 40700)
70 // g++ 4.4, 4.6 fail these tests with optimizations on
74 BOOST_TEST( boost::core::signbit( x
) );
76 BOOST_TEST_EQ( boost::core::copysign( T(+2), x
), T(-2) );
77 BOOST_TEST_EQ( boost::core::copysign( T(-2), x
), T(-2) );
82 template<class T
> void test_positive_infinity( T x
)
84 BOOST_TEST( !boost::core::isfinite( x
) );
85 BOOST_TEST( boost::core::isinf( x
) );
86 BOOST_TEST( !boost::core::isnan( x
) );
87 BOOST_TEST( !boost::core::isnormal( x
) );
89 BOOST_TEST_EQ( boost::core::fpclassify( x
), boost::core::fp_infinite
);
91 BOOST_TEST( !boost::core::signbit( x
) );
93 BOOST_TEST_EQ( boost::core::copysign( T(+2), x
), T(+2) );
94 BOOST_TEST_EQ( boost::core::copysign( T(-2), x
), T(+2) );
97 template<class T
> void test_negative_infinity( T x
)
99 BOOST_TEST( !boost::core::isfinite( x
) );
100 BOOST_TEST( boost::core::isinf( x
) );
101 BOOST_TEST( !boost::core::isnan( x
) );
102 BOOST_TEST( !boost::core::isnormal( x
) );
104 BOOST_TEST_EQ( boost::core::fpclassify( x
), boost::core::fp_infinite
);
106 BOOST_TEST( boost::core::signbit( x
) );
108 BOOST_TEST_EQ( boost::core::copysign( T(+2), x
), T(-2) );
109 BOOST_TEST_EQ( boost::core::copysign( T(-2), x
), T(-2) );
112 template<class T
> void test_positive_nan( T x
)
114 BOOST_TEST( !boost::core::isfinite( x
) );
115 BOOST_TEST( !boost::core::isinf( x
) );
116 BOOST_TEST( boost::core::isnan( x
) );
117 BOOST_TEST( !boost::core::isnormal( x
) );
119 BOOST_TEST_EQ( boost::core::fpclassify( x
), boost::core::fp_nan
);
121 BOOST_TEST( !boost::core::signbit( x
) );
123 BOOST_TEST_EQ( boost::core::copysign( T(+2), x
), T(+2) );
124 BOOST_TEST_EQ( boost::core::copysign( T(-2), x
), T(+2) );
127 template<class T
> void test_negative_nan( T x
)
129 BOOST_TEST( !boost::core::isfinite( x
) );
130 BOOST_TEST( !boost::core::isinf( x
) );
131 BOOST_TEST( boost::core::isnan( x
) );
132 BOOST_TEST( !boost::core::isnormal( x
) );
134 BOOST_TEST_EQ( boost::core::fpclassify( x
), boost::core::fp_nan
);
136 BOOST_TEST( boost::core::signbit( x
) );
138 BOOST_TEST_EQ( boost::core::copysign( T(+2), x
), T(-2) );
139 BOOST_TEST_EQ( boost::core::copysign( T(-2), x
), T(-2) );
142 template<class T
> void test_positive_subnormal( T x
)
144 BOOST_TEST( boost::core::isfinite( x
) );
145 BOOST_TEST( !boost::core::isinf( x
) );
146 BOOST_TEST( !boost::core::isnan( x
) );
147 BOOST_TEST( !boost::core::isnormal( x
) );
149 BOOST_TEST_EQ( boost::core::fpclassify( x
), boost::core::fp_subnormal
);
151 BOOST_TEST( !boost::core::signbit( x
) );
153 BOOST_TEST_EQ( boost::core::copysign( T(+2), x
), T(+2) );
154 BOOST_TEST_EQ( boost::core::copysign( T(-2), x
), T(+2) );
157 template<class T
> void test_negative_subnormal( T x
)
159 BOOST_TEST( boost::core::isfinite( x
) );
160 BOOST_TEST( !boost::core::isinf( x
) );
161 BOOST_TEST( !boost::core::isnan( x
) );
162 BOOST_TEST( !boost::core::isnormal( x
) );
164 BOOST_TEST_EQ( boost::core::fpclassify( x
), boost::core::fp_subnormal
);
166 BOOST_TEST( boost::core::signbit( x
) );
168 BOOST_TEST_EQ( boost::core::copysign( T(+2), x
), T(-2) );
169 BOOST_TEST_EQ( boost::core::copysign( T(-2), x
), T(-2) );
172 template<class T
> void test_positive_normal_( T x
)
174 test_positive_normal( x
);
175 test_positive_normal( boost::core::copysign( x
, T(+1) ) );
176 test_negative_normal( boost::core::copysign( x
, T(-1) ) );
179 template<class T
> void test_negative_normal_( T x
)
181 test_negative_normal( x
);
182 test_positive_normal( boost::core::copysign( x
, T(+1) ) );
183 test_negative_normal( boost::core::copysign( x
, T(-1) ) );
186 template<class T
> void test_positive_zero_( T x
)
188 test_positive_zero( x
);
189 test_positive_zero( boost::core::copysign( x
, T(+1) ) );
190 test_negative_zero( boost::core::copysign( x
, T(-1) ) );
193 template<class T
> void test_negative_zero_( T x
)
195 test_negative_zero( x
);
196 test_positive_zero( boost::core::copysign( x
, T(+1) ) );
197 test_negative_zero( boost::core::copysign( x
, T(-1) ) );
200 template<class T
> void test_positive_infinity_( T x
)
202 test_positive_infinity( x
);
203 test_positive_infinity( boost::core::copysign( x
, T(+1) ) );
204 test_negative_infinity( boost::core::copysign( x
, T(-1) ) );
207 template<class T
> void test_negative_infinity_( T x
)
209 test_negative_infinity( x
);
210 test_positive_infinity( boost::core::copysign( x
, T(+1) ) );
211 test_negative_infinity( boost::core::copysign( x
, T(-1) ) );
214 template<class T
> void test_positive_nan_( T x
)
216 test_positive_nan( x
);
217 test_positive_nan( boost::core::copysign( x
, T(+1) ) );
218 test_negative_nan( boost::core::copysign( x
, T(-1) ) );
221 template<class T
> void test_negative_nan_( T x
)
223 test_negative_nan( x
);
224 test_positive_nan( boost::core::copysign( x
, T(+1) ) );
225 test_negative_nan( boost::core::copysign( x
, T(-1) ) );
228 template<class T
> void test_positive_subnormal_( T x
)
230 test_positive_subnormal( x
);
231 test_positive_subnormal( boost::core::copysign( x
, T(+1) ) );
232 test_negative_subnormal( boost::core::copysign( x
, T(-1) ) );
235 template<class T
> void test_negative_subnormal_( T x
)
237 test_negative_subnormal( x
);
238 test_positive_subnormal( boost::core::copysign( x
, T(+1) ) );
239 test_negative_subnormal( boost::core::copysign( x
, T(-1) ) );
246 test_positive_normal_( +1.0f
);
247 test_negative_normal_( -1.0f
);
248 test_positive_normal_( FLT_MIN
);
249 test_negative_normal_( -FLT_MIN
);
250 test_positive_normal_( FLT_MAX
);
251 test_negative_normal_( -FLT_MAX
);
252 test_positive_zero_( +0.0f
);
253 test_negative_zero_( -0.0f
);
254 test_positive_infinity_( std::numeric_limits
<float>::infinity() );
255 test_negative_infinity_( -std::numeric_limits
<float>::infinity() );
256 test_positive_nan_( std::numeric_limits
<float>::quiet_NaN() );
257 test_negative_nan_( boost::core::copysign( std::numeric_limits
<float>::quiet_NaN(), -1.0f
) );
258 test_positive_subnormal_( FLT_MIN
/ 2 );
259 test_negative_subnormal_( -FLT_MIN
/ 2 );
263 test_positive_normal_( +1.0 );
264 test_negative_normal_( -1.0 );
265 test_positive_normal_( DBL_MIN
);
266 test_negative_normal_( -DBL_MIN
);
267 test_positive_normal_( DBL_MAX
);
268 test_negative_normal_( -DBL_MAX
);
269 test_positive_zero_( +0.0 );
270 test_negative_zero_( -0.0 );
271 test_positive_infinity_( std::numeric_limits
<double>::infinity() );
272 test_negative_infinity_( -std::numeric_limits
<double>::infinity() );
273 test_positive_nan_( std::numeric_limits
<double>::quiet_NaN() );
274 test_negative_nan_( boost::core::copysign( std::numeric_limits
<double>::quiet_NaN(), -1.0 ) );
275 test_positive_subnormal_( DBL_MIN
/ 2 );
276 test_negative_subnormal_( -DBL_MIN
/ 2 );
280 test_positive_normal_( +1.0l );
281 test_negative_normal_( -1.0l );
282 test_positive_normal_( LDBL_MIN
);
283 test_negative_normal_( -LDBL_MIN
);
284 test_positive_normal_( LDBL_MAX
);
285 test_negative_normal_( -LDBL_MAX
);
286 test_positive_zero_( +0.0l );
287 test_negative_zero_( -0.0l );
288 test_positive_infinity_( std::numeric_limits
<long double>::infinity() );
289 test_negative_infinity_( -std::numeric_limits
<long double>::infinity() );
290 test_positive_nan_( std::numeric_limits
<long double>::quiet_NaN() );
291 test_negative_nan_( boost::core::copysign( std::numeric_limits
<long double>::quiet_NaN(), -1.0l ) );
292 test_positive_subnormal_( LDBL_MIN
/ 2 );
293 test_negative_subnormal_( -LDBL_MIN
/ 2 );
295 return boost::report_errors();