isnormal.hpp 1.2 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_ISNORMAL_HPP
  6. #define BOOST_MATH_ISNORMAL_HPP
  7. #include <boost/math/ccmath/detail/config.hpp>
  8. #ifdef BOOST_MATH_NO_CCMATH
  9. #error "The header <boost/math/isnormal.hpp> can only be used in C++17 and later."
  10. #endif
  11. #include <boost/math/ccmath/abs.hpp>
  12. #include <boost/math/ccmath/isinf.hpp>
  13. #include <boost/math/ccmath/isnan.hpp>
  14. namespace boost::math::ccmath {
  15. template <typename T>
  16. inline constexpr bool isnormal(T x)
  17. {
  18. if(BOOST_MATH_IS_CONSTANT_EVALUATED(x))
  19. {
  20. return x == T(0) ? false :
  21. boost::math::ccmath::isinf(x) ? false :
  22. boost::math::ccmath::isnan(x) ? false :
  23. boost::math::ccmath::abs(x) < (std::numeric_limits<T>::min)() ? false : true;
  24. }
  25. else
  26. {
  27. using std::isnormal;
  28. if constexpr (!std::is_integral_v<T>)
  29. {
  30. return isnormal(x);
  31. }
  32. else
  33. {
  34. return isnormal(static_cast<double>(x));
  35. }
  36. }
  37. }
  38. }
  39. #endif // BOOST_MATH_ISNORMAL_HPP