isnan.hpp 1.0 KB

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