]>
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/isfinite.hpp> | |
12 | ||
13 | #ifdef BOOST_HAS_FLOAT128 | |
14 | #include <boost/multiprecision/float128.hpp> | |
15 | #endif | |
16 | ||
17 | template <typename T> | |
18 | void test() | |
19 | { | |
20 | if constexpr (std::numeric_limits<T>::has_quiet_NaN) | |
21 | { | |
22 | static_assert(!boost::math::ccmath::isfinite(std::numeric_limits<T>::quiet_NaN()), "Wrong response to NAN"); | |
23 | } | |
24 | ||
25 | static_assert(boost::math::ccmath::isfinite(T(0)), "Wrong response to 0"); | |
26 | ||
27 | if constexpr (!std::is_integral_v<T>) | |
28 | { | |
29 | static_assert(boost::math::ccmath::isfinite((std::numeric_limits<T>::min)()/2), "Wrong response to subnormal"); | |
30 | static_assert(!boost::math::ccmath::isfinite(std::numeric_limits<T>::infinity()), "Wrong response to infinity"); | |
31 | } | |
32 | else | |
33 | { | |
34 | // Integer types define infinity as 0 | |
35 | // https://en.cppreference.com/w/cpp/types/numeric_limits/infinity | |
36 | static_assert(boost::math::ccmath::isfinite(std::numeric_limits<T>::infinity()), "Wrong response to infinity"); | |
37 | } | |
38 | } | |
39 | ||
40 | #ifndef BOOST_MATH_NO_CONSTEXPR_DETECTION | |
41 | int main() | |
42 | { | |
43 | test<float>(); | |
44 | test<double>(); | |
45 | ||
46 | #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS | |
47 | test<long double>(); | |
48 | #endif | |
49 | ||
50 | #if defined(BOOST_HAS_FLOAT128) && !defined(BOOST_MATH_USING_BUILTIN_CONSTANT_P) | |
51 | test<boost::multiprecision::float128>(); | |
52 | #endif | |
53 | ||
54 | test<int>(); | |
55 | test<unsigned>(); | |
56 | test<long>(); | |
57 | test<std::int32_t>(); | |
58 | test<std::int64_t>(); | |
59 | test<std::uint32_t>(); | |
60 | ||
61 | return 0; | |
62 | } | |
63 | #else | |
64 | int main() | |
65 | { | |
66 | return 0; | |
67 | } | |
68 | #endif |