brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 6ec6fca Raw
61 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_ILOGB_HPP7#define BOOST_MATH_CCMATH_ILOGB_HPP8 9#include <boost/math/ccmath/detail/config.hpp>10 11#ifdef BOOST_MATH_NO_CCMATH12#error "The header <boost/math/ilogb.hpp> can only be used in C++17 and later."13#endif14 15#include <boost/math/ccmath/logb.hpp>16#include <boost/math/ccmath/isinf.hpp>17#include <boost/math/ccmath/isnan.hpp>18#include <boost/math/ccmath/abs.hpp>19 20namespace boost::math::ccmath {21 22// If arg is not zero, infinite, or NaN, the value returned is exactly equivalent to static_cast<int>(std::logb(arg))23template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>24inline constexpr int ilogb(Real arg) noexcept25{26    if(BOOST_MATH_IS_CONSTANT_EVALUATED(arg))27    {28        return boost::math::ccmath::abs(arg) == Real(0) ? FP_ILOGB0 :29               boost::math::ccmath::isinf(arg) ? INT_MAX :30               boost::math::ccmath::isnan(arg) ? FP_ILOGBNAN :31               static_cast<int>(boost::math::ccmath::logb(arg));32    }33    else34    {35        using std::ilogb;36        return ilogb(arg);37    }38}39 40template <typename Z, std::enable_if_t<std::is_integral_v<Z>, bool> = true>41inline constexpr int ilogb(Z arg) noexcept42{43    return boost::math::ccmath::ilogb(static_cast<double>(arg));44}45 46inline constexpr int ilogbf(float arg) noexcept47{48    return boost::math::ccmath::ilogb(arg);49}50 51#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS52inline constexpr int ilogbl(long double arg) noexcept53{54    return boost::math::ccmath::ilogb(arg);55}56#endif57 58} // Namespaces59 60#endif // BOOST_MATH_CCMATH_ILOGB_HPP61