| 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_ISINF |
| 7 | #define BOOST_MATH_CCMATH_ISINF |
| 8 | |
| 9 | #include <boost/math/special_functions/fpclassify.hpp> |
| 10 | #include <boost/math/ccmath/detail/config.hpp> |
| 11 | |
| 12 | #ifdef BOOST_MATH_NO_CCMATH |
| 13 | #error "The header <boost/math/isinf.hpp> can only be used in C++17 and later." |
| 14 | #endif |
| 15 | |
| 16 | namespace boost::math::ccmath { |
| 17 | |
| 18 | template <typename T> |
| 19 | constexpr bool isinf BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x) noexcept |
| 20 | { |
| 21 | if(BOOST_MATH_IS_CONSTANT_EVALUATED(x)) |
| 22 | { |
| 23 | if constexpr (std::numeric_limits<T>::is_signed) |
| 24 | { |
| 25 | return x == std::numeric_limits<T>::infinity() || -x == std::numeric_limits<T>::infinity(); |
| 26 | } |
| 27 | else |
| 28 | { |
| 29 | return x == std::numeric_limits<T>::infinity(); |
| 30 | } |
| 31 | } |
| 32 | else |
| 33 | { |
| 34 | using boost::math::isinf; |
| 35 | |
| 36 | if constexpr (!std::is_integral_v<T>) |
| 37 | { |
| 38 | return (isinf)(x); |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | return (isinf)(static_cast<double>(x)); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | } |
| 48 | |
| 49 | #endif // BOOST_MATH_CCMATH_ISINF |
| 50 |
