]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/math/ccmath/scalbn.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / math / ccmath / scalbn.hpp
CommitLineData
1e59de90
TL
1// (C) Copyright Matt Borland 2021.
2// (C) Copyright John Maddock 2021.
3// Use, modification and distribution are subject to the
4// Boost Software License, Version 1.0. (See accompanying file
5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7#ifndef BOOST_MATH_CCMATH_SCALBN_HPP
8#define BOOST_MATH_CCMATH_SCALBN_HPP
9
10#include <cmath>
11#include <cfloat>
12#include <limits>
13#include <type_traits>
14#include <boost/math/tools/is_constant_evaluated.hpp>
15#include <boost/math/ccmath/abs.hpp>
16#include <boost/math/ccmath/isinf.hpp>
17#include <boost/math/ccmath/isnan.hpp>
18
19namespace boost::math::ccmath {
20
21namespace detail {
22
23template <typename Real, typename Z>
24inline constexpr Real scalbn_impl(Real arg, Z exp) noexcept
25{
26 while(exp > 0)
27 {
28 arg *= FLT_RADIX;
29 --exp;
30 }
31 while(exp < 0)
32 {
33 arg /= FLT_RADIX;
34 ++exp;
35 }
36
37 return arg;
38}
39
40} // Namespace detail
41
42template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>
43inline constexpr Real scalbn(Real arg, int exp) noexcept
44{
45 if(BOOST_MATH_IS_CONSTANT_EVALUATED(arg))
46 {
47 return boost::math::ccmath::abs(arg) == Real(0) ? arg :
48 boost::math::ccmath::isinf(arg) ? arg :
49 boost::math::ccmath::isnan(arg) ? arg :
50 boost::math::ccmath::detail::scalbn_impl(arg, exp);
51 }
52 else
53 {
54 using std::scalbn;
55 return scalbn(arg, exp);
56 }
57}
58
59template <typename Z, std::enable_if_t<std::is_integral_v<Z>, bool> = true>
60inline constexpr double scalbn(Z arg, int exp) noexcept
61{
62 return boost::math::ccmath::scalbn(static_cast<double>(arg), exp);
63}
64
65inline constexpr float scalbnf(float arg, int exp) noexcept
66{
67 return boost::math::ccmath::scalbn(arg, exp);
68}
69
70#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
71inline constexpr long double scalbnl(long double arg, int exp) noexcept
72{
73 return boost::math::ccmath::scalbn(arg, exp);
74}
75#endif
76
77} // Namespaces
78
79#endif // BOOST_MATH_CCMATH_SCALBN_HPP