12 #if !defined(CNL_IMPL_SCALED_INTEGER_EXTRAS_H)
13 #define CNL_IMPL_SCALED_INTEGER_EXTRAS_H
15 #include "../cmath/abs.h"
16 #include "../config.h"
17 #include "../num_traits/width.h"
18 #include "definition.h"
22 #if defined(CNL_IOSTREAMS_ENABLED)
42 template<
typename Rep,
class Scale>
51 template<
class Rep,
int Exponent,
int Radix>
52 requires(Exponent < 0)
53 [[nodiscard]] constexpr
auto floor(
scaled_integer<Rep, power<Exponent, Radix>>
const& x)
56 Radix == 2,
"cnl::floor(scaled_integer<Rep, power<Exponent, Radix>>) not "
57 "implemented for Exponent<0 && Radix!=2");
60 return _impl::from_rep<scaled_integer<Rep, power<0, Radix>>>(
61 _impl::to_rep(x) >> constant<-Exponent>());
65 template<
class Rep,
int Exponent,
int Radix>
66 requires(Exponent >= 0)
84 requires(NumBits <=
sizeof(
float) * CHAR_BIT)
struct float_of_size<NumBits> {
89 requires(
sizeof(
float) * CHAR_BIT < NumBits && NumBits <=
sizeof(
double) * CHAR_BIT)
struct float_of_size<NumBits> {
94 requires(
sizeof(
double) * CHAR_BIT < NumBits && NumBits <=
sizeof(
long double) * CHAR_BIT)
struct float_of_size<NumBits> {
95 using type =
long double;
99 using float_of_same_size =
typename float_of_size<_impl::width<T>>::type;
102 typename Rep,
int Exponent,
int Radix,
103 _impl::float_of_same_size<Rep> (*F)(_impl::float_of_same_size<Rep>)>
104 [[nodiscard]] constexpr
auto
105 crib(
scaled_integer<Rep, power<Exponent, Radix>>
const& x) noexcept
107 using fp = _impl::float_of_same_size<Rep>;
108 return static_cast<scaled_integer<Rep, power<Exponent, Radix>
>>(
109 F(
static_cast<fp
>(x)));
113 template<
typename Rep,
int Exponent,
int Radix>
114 [[nodiscard]] constexpr
auto sin(
scaled_integer<Rep, power<Exponent, Radix>>
const& x) noexcept
116 return _impl::crib<Rep, Exponent, Radix, std::sin>(x);
119 template<
typename Rep,
int Exponent,
int Radix>
120 [[nodiscard]] constexpr
auto cos(
scaled_integer<Rep, power<Exponent, Radix>>
const& x) noexcept
122 return _impl::crib<Rep, Exponent, Radix, std::cos>(x);
125 template<
typename Rep,
int Exponent,
int Radix>
126 [[nodiscard]] constexpr
auto exp(
scaled_integer<Rep, power<Exponent, Radix>>
const& x) noexcept
128 return _impl::crib<Rep, Exponent, Radix, std::exp>(x);
131 template<
typename Rep,
int Exponent,
int Radix>
132 [[nodiscard]] constexpr
auto pow(
scaled_integer<Rep, power<Exponent, Radix>>
const& x) noexcept
134 return _impl::crib<Rep, Exponent, Radix, std::pow>(x);
140 #if defined(CNL_IOSTREAMS_ENABLED)
141 template<
typename Rep,
int Exponent,
int Radix>
144 return out << to_chars_static(fp).chars.data();
147 template<
typename Rep,
int Exponent,
int Radix>
158 #endif // CNL_IMPL_SCALED_INTEGER_EXTRAS_H