Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:45:15

0001 //  (C) Copyright Matt Borland 2021.
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_MATH_CCMATH_ILOGB_HPP
0007 #define BOOST_MATH_CCMATH_ILOGB_HPP
0008 
0009 #include <boost/math/ccmath/detail/config.hpp>
0010 
0011 #ifdef BOOST_MATH_NO_CCMATH
0012 #error "The header <boost/math/ilogb.hpp> can only be used in C++17 and later."
0013 #endif
0014 
0015 #include <boost/math/ccmath/logb.hpp>
0016 #include <boost/math/ccmath/isinf.hpp>
0017 #include <boost/math/ccmath/isnan.hpp>
0018 #include <boost/math/ccmath/abs.hpp>
0019 
0020 namespace boost::math::ccmath {
0021 
0022 // If arg is not zero, infinite, or NaN, the value returned is exactly equivalent to static_cast<int>(std::logb(arg))
0023 template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>
0024 inline constexpr int ilogb(Real arg) noexcept
0025 {
0026     if(BOOST_MATH_IS_CONSTANT_EVALUATED(arg))
0027     {
0028         return boost::math::ccmath::abs(arg) == Real(0) ? FP_ILOGB0 :
0029                boost::math::ccmath::isinf(arg) ? INT_MAX :
0030                boost::math::ccmath::isnan(arg) ? FP_ILOGBNAN :
0031                static_cast<int>(boost::math::ccmath::logb(arg));
0032     }
0033     else
0034     {
0035         using std::ilogb;
0036         return ilogb(arg);
0037     }
0038 }
0039 
0040 template <typename Z, std::enable_if_t<std::is_integral_v<Z>, bool> = true>
0041 inline constexpr int ilogb(Z arg) noexcept
0042 {
0043     return boost::math::ccmath::ilogb(static_cast<double>(arg));
0044 }
0045 
0046 inline constexpr int ilogbf(float arg) noexcept
0047 {
0048     return boost::math::ccmath::ilogb(arg);
0049 }
0050 
0051 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
0052 inline constexpr int ilogbl(long double arg) noexcept
0053 {
0054     return boost::math::ccmath::ilogb(arg);
0055 }
0056 #endif
0057 
0058 } // Namespaces
0059 
0060 #endif // BOOST_MATH_CCMATH_ILOGB_HPP