isinf.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <cmath>
  8. #include <limits>
  9. #include <type_traits>
  10. #include <boost/math/tools/is_constant_evaluated.hpp>
  11. #include <boost/math/tools/is_standalone.hpp>
  12. #ifndef BOOST_MATH_STANDALONE
  13. #include <boost/config.hpp>
  14. #ifdef BOOST_NO_CXX17_IF_CONSTEXPR
  15. #error "The header <boost/math/norms.hpp> can only be used in C++17 and later."
  16. #endif
  17. #endif
  18. namespace boost::math::ccmath {
  19. template <typename T>
  20. constexpr bool isinf(T x) noexcept
  21. {
  22. if(BOOST_MATH_IS_CONSTANT_EVALUATED(x))
  23. {
  24. if constexpr (std::numeric_limits<T>::is_signed)
  25. {
  26. return x == std::numeric_limits<T>::infinity() || -x == std::numeric_limits<T>::infinity();
  27. }
  28. else
  29. {
  30. return x == std::numeric_limits<T>::infinity();
  31. }
  32. }
  33. else
  34. {
  35. using std::isinf;
  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. #endif // BOOST_MATH_CCMATH_ISINF