brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · cf5a4d1 Raw
48 lines · plain
1//  (C) Copyright Matt Borland 2021.2//  Use, modification and distribution are subject to the3//  Boost Software License, Version 1.0. (See accompanying file4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)5 6#ifndef BOOST_MATH_ISNORMAL_HPP7#define BOOST_MATH_ISNORMAL_HPP8 9#include <boost/math/ccmath/detail/config.hpp>10 11#ifdef BOOST_MATH_NO_CCMATH12#error "The header <boost/math/isnormal.hpp> can only be used in C++17 and later."13#endif14 15#include <boost/math/ccmath/abs.hpp>16#include <boost/math/ccmath/isinf.hpp>17#include <boost/math/ccmath/isnan.hpp>18 19namespace boost::math::ccmath {20 21template <typename T>22inline 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    else32    {33        using std::isnormal;34 35        if constexpr (!std::is_integral_v<T>)36        {37            return isnormal(x);38        }39        else40        {41            return isnormal(static_cast<double>(x));42        }43    }44}45}46 47#endif // BOOST_MATH_ISNORMAL_HPP48