isinf.hpp 1.6 KB

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