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