| 1 |
// (C) Copyright Matt Borland 2021. |
| 2 |
// Use, modification and distribution are subject to the |
| 3 |
// Boost Software License, Version 1.0. (See accompanying file |
| 4 |
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 |
|
| 6 |
#ifndef BOOST_MATH_CCMATH_SCALBLN_HPP |
| 7 |
#define BOOST_MATH_CCMATH_SCALBLN_HPP |
| 8 |
|
| 9 |
#include <boost/math/ccmath/detail/config.hpp> |
| 10 |
|
| 11 |
#ifdef BOOST_MATH_NO_CCMATH |
| 12 |
#error "The header <boost/math/scalbln.hpp> can only be used in C++17 and later." |
| 13 |
#endif |
| 14 |
|
| 15 |
#include <cfloat> |
| 16 |
#include <boost/math/ccmath/scalbn.hpp> |
| 17 |
#include <boost/math/ccmath/abs.hpp> |
| 18 |
#include <boost/math/ccmath/isinf.hpp> |
| 19 |
#include <boost/math/ccmath/isnan.hpp> |
| 20 |
|
| 21 |
namespace boost::math::ccmath { |
| 22 |
|
| 23 |
template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true> |
| 24 |
inline constexpr Real scalbln(Real arg, long exp) noexcept |
| 25 |
{ |
| 26 |
if(BOOST_MATH_IS_CONSTANT_EVALUATED(arg)) |
| 27 |
{ |
| 28 |
return boost::math::ccmath::abs(arg) == Real(0) ? arg : |
| 29 |
boost::math::ccmath::isinf(arg) ? arg : |
| 30 |
boost::math::ccmath::isnan(arg) ? arg : |
| 31 |
boost::math::ccmath::detail::scalbn_impl(arg, exp); |
| 32 |
} |
| 33 |
else |
| 34 |
{ |
| 35 |
using std::scalbln; |
| 36 |
return scalbln(arg, exp); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
template <typename Z, std::enable_if_t<std::is_integral_v<Z>, bool> = true> |
| 41 |
inline constexpr double scalbln(Z arg, long exp) noexcept |
| 42 |
{ |
| 43 |
return boost::math::ccmath::scalbln(static_cast<double>(arg), exp); |
| 44 |
} |
| 45 |
|
| 46 |
inline constexpr float scalblnf(float arg, long exp) noexcept |
| 47 |
{ |
| 48 |
return boost::math::ccmath::scalbln(arg, exp); |
| 49 |
} |
| 50 |
|
| 51 |
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS |
| 52 |
inline constexpr long double scalblnl(long double arg, long exp) noexcept |
| 53 |
{ |
| 54 |
return boost::math::ccmath::scalbln(arg, exp); |
| 55 |
} |
| 56 |
#endif |
| 57 |
|
| 58 |
} // Namespaces |
| 59 |
|
| 60 |
#endif // BOOST_MATH_CCMATH_SCALBLN_HPP |