49 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_CCMATH_FPCLASSIFY7#define BOOST_MATH_CCMATH_FPCLASSIFY8 9#include <boost/math/ccmath/detail/config.hpp>10 11#ifdef BOOST_MATH_NO_CCMATH12#error "The header <boost/math/fpclassify.hpp> can only be used in C++17 and later."13#endif14 15#include <boost/math/special_functions/fpclassify.hpp>16#include <boost/math/ccmath/abs.hpp>17#include <boost/math/ccmath/isinf.hpp>18#include <boost/math/ccmath/isnan.hpp>19#include <boost/math/ccmath/isfinite.hpp>20 21namespace boost::math::ccmath {22 23template <typename T, std::enable_if_t<!std::is_integral_v<T>, bool> = true>24inline constexpr int fpclassify BOOST_MATH_PREVENT_MACRO_SUBSTITUTION(T x)25{26 if(BOOST_MATH_IS_CONSTANT_EVALUATED(x))27 {28 return (boost::math::ccmath::isnan)(x) ? FP_NAN :29 (boost::math::ccmath::isinf)(x) ? FP_INFINITE :30 boost::math::ccmath::abs(x) == T(0) ? FP_ZERO :31 boost::math::ccmath::abs(x) > 0 && boost::math::ccmath::abs(x) < (std::numeric_limits<T>::min)() ? FP_SUBNORMAL : FP_NORMAL;32 }33 else34 {35 using boost::math::fpclassify;36 return (fpclassify)(x);37 }38}39 40template <typename Z, std::enable_if_t<std::is_integral_v<Z>, bool> = true>41inline constexpr int fpclassify(Z x)42{43 return boost::math::ccmath::fpclassify(static_cast<double>(x));44}45 46}47 48#endif // BOOST_MATH_CCMATH_FPCLASSIFY49