isnan.hpp 998 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_ISNAN
  6. #define BOOST_MATH_CCMATH_ISNAN
  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/isnan.hpp> can only be used in C++17 and later."
  11. #endif
  12. namespace boost::math::ccmath {
  13. template <typename T>
  14. inline constexpr bool isnan BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x)
  15. {
  16. if(BOOST_MATH_IS_CONSTANT_EVALUATED(x))
  17. {
  18. return x != x;
  19. }
  20. else
  21. {
  22. using boost::math::isnan;
  23. if constexpr (!std::is_integral_v<T>)
  24. {
  25. return (isnan)(x);
  26. }
  27. else
  28. {
  29. return (isnan)(static_cast<double>(x));
  30. }
  31. }
  32. }
  33. }
  34. #endif // BOOST_MATH_CCMATH_ISNAN