/////////////////////////////////////////////////////////////////////////////// // Copyright 2022 Matt Borland. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_MP_DETAIL_FPCLASSIFY_HPP #define BOOST_MP_DETAIL_FPCLASSIFY_HPP #include #include #include #include #include #ifdef BOOST_MP_MATH_AVAILABLE #include #define BOOST_MP_ISNAN(x) (boost::math::isnan)(x) #define BOOST_MP_ISINF(x) (boost::math::isinf)(x) #define BOOST_MP_FPCLASSIFY(x) (boost::math::fpclassify)(x) #define BOOST_MP_ISFINITE(x) (!(boost::math::isnan)(x) && !(boost::math::isinf)(x)) #else namespace boost { namespace multiprecision { namespace detail { template ::value #ifdef BOOST_HAS_FLOAT128 || std::is_same::value #endif , bool>::type = true> inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION (const T x) { BOOST_MP_FLOAT128_USING; using std::isnan; return static_cast((isnan)(x)); } template ::value #ifdef BOOST_HAS_FLOAT128 && !std::is_same::value #endif , bool>::type = true> inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION (const T x) { return x != x; } template ::value #ifdef BOOST_HAS_FLOAT128 || std::is_same::value #endif , bool>::type = true> inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION (const T x) { BOOST_MP_FLOAT128_USING; using std::isinf; return static_cast((isinf)(x)); } template ::value #ifdef BOOST_HAS_FLOAT128 && !std::is_same::value #endif , bool>::type = true> inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION (const T x) { return x == std::numeric_limits::infinity() || x == -std::numeric_limits::infinity(); } template ::value, bool>::type = true> inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (const T x) { using std::fpclassify; return fpclassify(x); } template ::value, bool>::type = true> inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (const T x) { BOOST_MP_FLOAT128_USING; using std::isnan; using std::isinf; using std::abs; return (isnan)(x) ? FP_NAN : (isinf)(x) ? FP_INFINITE : abs(x) == T(0) ? FP_ZERO : abs(x) > 0 && abs(x) < (std::numeric_limits::min)() ? FP_SUBNORMAL : FP_NORMAL; } }}} // Namespace boost::multiprecision::detail #define BOOST_MP_ISNAN(x) (boost::multiprecision::detail::isnan)(x) #define BOOST_MP_ISINF(x) (boost::multiprecision::detail::isinf)(x) #define BOOST_MP_FPCLASSIFY(x) (boost::multiprecision::detail::fpclassify)(x) #define BOOST_MP_ISFINITE(x) (!(boost::multiprecision::detail::isnan)(x) && !(boost::multiprecision::detail::isinf)(x)) #endif #endif // BOOST_MP_DETAIL_FPCLASSIFY_HPP