]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // (C) Copyright Matt Borland 2021. |
2 | // Use, modification and distribution are subject to the | |
3 | // Boost Software License, Version 1.0. (See accompanying file | |
4 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #include <cmath> | |
7 | #include <cfloat> | |
8 | #include <cstdint> | |
9 | #include <limits> | |
10 | #include <type_traits> | |
11 | #include <boost/math/ccmath/isnormal.hpp> | |
12 | ||
13 | #ifdef BOOST_HAS_FLOAT128 | |
14 | #include <boost/multiprecision/float128.hpp> | |
15 | #endif | |
16 | ||
17 | // Determines if the given argument is normal, i.e. is neither zero, subnormal, infinite nor NaN. | |
18 | template <typename T> | |
19 | void test() | |
20 | { | |
21 | if constexpr (std::numeric_limits<T>::has_quiet_NaN) | |
22 | { | |
23 | static_assert(!boost::math::ccmath::isnormal(std::numeric_limits<T>::quiet_NaN()), "Wrong response to quiet NAN"); | |
24 | } | |
25 | ||
26 | static_assert(!boost::math::ccmath::isnormal(T(0)), "Wrong response to 0"); | |
27 | ||
28 | if constexpr (!std::is_integral_v<T>) | |
29 | { | |
30 | static_assert(!boost::math::ccmath::isnormal((std::numeric_limits<T>::min)() / 2), "Wrong response to subnormal"); | |
31 | static_assert(!boost::math::ccmath::isnormal(std::numeric_limits<T>::infinity()), "Wrong response to infinity"); | |
32 | } | |
33 | ||
34 | static_assert(boost::math::ccmath::isnormal(T(1)), "Wrong response to normal number"); | |
35 | } | |
36 | ||
37 | #ifndef BOOST_MATH_NO_CONSTEXPR_DETECTION | |
38 | int main() | |
39 | { | |
40 | test<float>(); | |
41 | test<double>(); | |
42 | ||
43 | #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS | |
44 | test<long double>(); | |
45 | #endif | |
46 | ||
47 | #if defined(BOOST_HAS_FLOAT128) && !defined(BOOST_MATH_USING_BUILTIN_CONSTANT_P) | |
48 | test<boost::multiprecision::float128>(); | |
49 | #endif | |
50 | ||
51 | test<int>(); | |
52 | test<unsigned>(); | |
53 | test<long>(); | |
54 | test<std::int32_t>(); | |
55 | test<std::int64_t>(); | |
56 | test<std::uint32_t>(); | |
57 | ||
58 | return 0; | |
59 | } | |
60 | #else | |
61 | int main() | |
62 | { | |
63 | return 0; | |
64 | } | |
65 | #endif |