| 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 |
#if defined(__clang_major__) && __clang_major__ >= 6 |
| 26 |
# pragma clang diagnostic push |
| 27 |
# pragma clang diagnostic ignored "-Wtautological-constant-compare" |
| 28 |
# if defined(__has_warning) |
| 29 |
# if __has_warning("-Wnan-infinity-disabled") |
| 30 |
# pragma clang diagnostic ignored "-Wnan-infinity-disabled" |
| 31 |
# endif |
| 32 |
# endif |
| 33 |
#endif |
| 34 |
return x == std::numeric_limits<T>::infinity() || -x == std::numeric_limits<T>::infinity(); |
| 35 |
#if defined(__clang_major__) && __clang_major__ >= 6 |
| 36 |
#pragma clang diagnostic pop |
| 37 |
#endif |
| 38 |
} |
| 39 |
else |
| 40 |
{ |
| 41 |
return x == std::numeric_limits<T>::infinity(); |
| 42 |
} |
| 43 |
} |
| 44 |
else |
| 45 |
{ |
| 46 |
using boost::math::isinf; |
| 47 |
|
| 48 |
if constexpr (!std::is_integral_v<T>) |
| 49 |
{ |
| 50 |
return (isinf)(x); |
| 51 |
} |
| 52 |
else |
| 53 |
{ |
| 54 |
return (isinf)(static_cast<double>(x)); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
#endif // BOOST_MATH_CCMATH_ISINF |