isinf.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. return x == std::numeric_limits<T>::infinity() || -x == std::numeric_limits<T>::infinity();
  21. }
  22. else
  23. {
  24. return x == std::numeric_limits<T>::infinity();
  25. }
  26. }
  27. else
  28. {
  29. using boost::math::isinf;
  30. if constexpr (!std::is_integral_v<T>)
  31. {
  32. return (isinf)(x);
  33. }
  34. else
  35. {
  36. return (isinf)(static_cast<double>(x));
  37. }
  38. }
  39. }
  40. }
  41. #endif // BOOST_MATH_CCMATH_ISINF