Debian Codegraph @

third-party/boost-math/include/boost/math/ccmath/isfinite.hpp

raw
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 #ifndef BOOST_MATH_CCMATH_ISFINITE
7 #define BOOST_MATH_CCMATH_ISFINITE
8
9 #include <boost/math/ccmath/detail/config.hpp>
10
11 #ifdef BOOST_MATH_NO_CCMATH
12 #error "The header <boost/math/isfinite.hpp> can only be used in C++17 and later."
13 #endif
14
15 #include <boost/math/ccmath/isinf.hpp>
16 #include <boost/math/ccmath/isnan.hpp>
17
18 namespace boost::math::ccmath {
19
20 template <typename T>
21 inline constexpr bool isfinite(T x)
22 {
23 if(BOOST_MATH_IS_CONSTANT_EVALUATED(x))
24 {
25 // bool isfinite (IntegralType arg) is a set of overloads accepting the arg argument of any integral type
26 // equivalent to casting the integral argument arg to double (e.g. static_cast<double>(arg))
27 if constexpr (std::is_integral_v<T>)
28 {
29 return !boost::math::ccmath::isinf(static_cast<double>(x)) && !boost::math::ccmath::isnan(static_cast<double>(x));
30 }
31 else
32 {
33 return !boost::math::ccmath::isinf(x) && !boost::math::ccmath::isnan(x);
34 }
35 }
36 else
37 {
38 using std::isfinite;
39
40 if constexpr (!std::is_integral_v<T>)
41 {
42 return isfinite(x);
43 }
44 else
45 {
46 return isfinite(static_cast<double>(x));
47 }
48 }
49 }
50
51 }
52
53 #endif // BOOST_MATH_CCMATH_ISFINITE