62 lines · plain
1// (C) Copyright Matt Borland 2021.2// Use, modification and distribution are subject to the3// Boost Software License, Version 1.0. (See accompanying file4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)5 6#ifndef BOOST_MATH_CCMATH_ISINF7#define BOOST_MATH_CCMATH_ISINF8 9#include <boost/math/special_functions/fpclassify.hpp>10#include <boost/math/ccmath/detail/config.hpp>11 12#ifdef BOOST_MATH_NO_CCMATH13#error "The header <boost/math/isinf.hpp> can only be used in C++17 and later."14#endif15 16namespace boost::math::ccmath {17 18template <typename T>19constexpr bool isinf BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x) noexcept20{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__ >= 626# pragma clang diagnostic push27# 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# endif32# endif33#endif34 return x == std::numeric_limits<T>::infinity() || -x == std::numeric_limits<T>::infinity();35#if defined(__clang_major__) && __clang_major__ >= 636#pragma clang diagnostic pop37#endif38 }39 else40 {41 return x == std::numeric_limits<T>::infinity();42 }43 }44 else45 {46 using boost::math::isinf;47 48 if constexpr (!std::is_integral_v<T>)49 {50 return (isinf)(x);51 }52 else53 {54 return (isinf)(static_cast<double>(x));55 }56 }57}58 59}60 61#endif // BOOST_MATH_CCMATH_ISINF62