1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright 2022 Matt Borland. Distributed under the Boost
3 // Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_MP_DETAIL_FPCLASSIFY_HPP
7 #define BOOST_MP_DETAIL_FPCLASSIFY_HPP
11 #include <type_traits>
12 #include <boost/multiprecision/detail/standalone_config.hpp>
13 #include <boost/multiprecision/detail/float128_functions.hpp>
15 #ifdef BOOST_MP_MATH_AVAILABLE
16 #include <boost/math/special_functions/fpclassify.hpp>
18 #define BOOST_MP_ISNAN(x) (boost::math::isnan)(x)
19 #define BOOST_MP_ISINF(x) (boost::math::isinf)(x)
20 #define BOOST_MP_FPCLASSIFY(x) (boost::math::fpclassify)(x)
21 #define BOOST_MP_ISFINITE(x) (!(boost::math::isnan)(x) && !(boost::math::isinf)(x))
25 namespace boost { namespace multiprecision { namespace detail {
27 template <typename T, typename std::enable_if<std::is_floating_point<T>::value
28 #ifdef BOOST_HAS_FLOAT128
29 || std::is_same<T, float128_type>::value
32 inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
34 BOOST_MP_FLOAT128_USING;
36 return static_cast<bool>((isnan)(x));
39 template <typename T, typename std::enable_if<!std::is_floating_point<T>::value
40 #ifdef BOOST_HAS_FLOAT128
41 && !std::is_same<T, float128_type>::value
44 inline bool isnan BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
49 template <typename T, typename std::enable_if<std::is_floating_point<T>::value
50 #ifdef BOOST_HAS_FLOAT128
51 || std::is_same<T, float128_type>::value
54 inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
56 BOOST_MP_FLOAT128_USING;
58 return static_cast<bool>((isinf)(x));
61 template <typename T, typename std::enable_if<!std::is_floating_point<T>::value
62 #ifdef BOOST_HAS_FLOAT128
63 && !std::is_same<T, float128_type>::value
66 inline bool isinf BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
68 return x == std::numeric_limits<T>::infinity() || x == -std::numeric_limits<T>::infinity();
71 template <typename T, typename std::enable_if<std::is_floating_point<T>::value, bool>::type = true>
72 inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
74 using std::fpclassify;
78 template <typename T, typename std::enable_if<!std::is_floating_point<T>::value, bool>::type = true>
79 inline int fpclassify BOOST_PREVENT_MACRO_SUBSTITUTION (const T x)
81 BOOST_MP_FLOAT128_USING;
86 return (isnan)(x) ? FP_NAN :
87 (isinf)(x) ? FP_INFINITE :
88 abs(x) == T(0) ? FP_ZERO :
89 abs(x) > 0 && abs(x) < (std::numeric_limits<T>::min)() ? FP_SUBNORMAL : FP_NORMAL;
92 }}} // Namespace boost::multiprecision::detail
94 #define BOOST_MP_ISNAN(x) (boost::multiprecision::detail::isnan)(x)
95 #define BOOST_MP_ISINF(x) (boost::multiprecision::detail::isinf)(x)
96 #define BOOST_MP_FPCLASSIFY(x) (boost::multiprecision::detail::fpclassify)(x)
97 #define BOOST_MP_ISFINITE(x) (!(boost::multiprecision::detail::isnan)(x) && !(boost::multiprecision::detail::isinf)(x))
101 #endif // BOOST_MP_DETAIL_FPCLASSIFY_HPP