brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 2026822 Raw
82 lines · plain
1//  (C) Copyright Matt Borland 2021.2//  (C) Copyright John Maddock 2021.3//  Use, modification and distribution are subject to the4//  Boost Software License, Version 1.0. (See accompanying file5//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)6 7#ifndef BOOST_MATH_CCMATH_SCALBN_HPP8#define BOOST_MATH_CCMATH_SCALBN_HPP9 10#include <boost/math/ccmath/detail/config.hpp>11 12#ifdef BOOST_MATH_NO_CCMATH13#error "The header <boost/math/scalbn.hpp> can only be used in C++17 and later."14#endif15 16#include <cfloat>17#include <boost/math/ccmath/abs.hpp>18#include <boost/math/ccmath/isinf.hpp>19#include <boost/math/ccmath/isnan.hpp>20 21namespace boost::math::ccmath {22 23namespace detail {24 25template <typename Real, typename Z>26inline constexpr Real scalbn_impl(Real arg, Z exp) noexcept27{28    while(exp > 0)29    {30        arg *= FLT_RADIX;31        --exp;32    }33    while(exp < 0)34    {35        arg /= FLT_RADIX;36        ++exp;37    }38 39    return arg;40}41 42} // Namespace detail43 44template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>45inline constexpr Real scalbn(Real arg, int exp) noexcept46{47    if(BOOST_MATH_IS_CONSTANT_EVALUATED(arg))48    {49        return boost::math::ccmath::abs(arg) == Real(0) ? arg :50               boost::math::ccmath::isinf(arg) ? arg :51               boost::math::ccmath::isnan(arg) ? arg :52               boost::math::ccmath::detail::scalbn_impl(arg, exp);53    }54    else55    {56        using std::scalbn;57        return scalbn(arg, exp);58    }59}60 61template <typename Z, std::enable_if_t<std::is_integral_v<Z>, bool> = true>62inline constexpr double scalbn(Z arg, int exp) noexcept63{64    return boost::math::ccmath::scalbn(static_cast<double>(arg), exp);65}66 67inline constexpr float scalbnf(float arg, int exp) noexcept68{69    return boost::math::ccmath::scalbn(arg, exp);70}71 72#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS73inline constexpr long double scalbnl(long double arg, int exp) noexcept74{75    return boost::math::ccmath::scalbn(arg, exp);76}77#endif78 79} // Namespaces80 81#endif // BOOST_MATH_CCMATH_SCALBN_HPP82