7 #if !defined(CNL_IMPL_NUM_TRAITS_FIXED_WIDTH_SCALE_H)
8 #define CNL_IMPL_NUM_TRAITS_FIXED_WIDTH_SCALE_H
12 #include "is_composite.h"
18 template<
int Digits,
int Radix,
class Scalar>
19 struct fixed_width_scale;
21 template<
int Digits,
int Radix,
typename S>
22 requires(!is_composite<S>::value)
struct fixed_width_scale<Digits, Radix, S> {
23 [[nodiscard]] constexpr
auto operator()(S
const& s)
const
26 Radix != 2 || digits_v<S> > -Digits,
27 "this operation will flush the given value");
29 return static_cast<S
>(scale<Digits, Radix, S>()(s));
34 template<
int Digits,
int Radix = 2,
class S>
35 [[nodiscard]] constexpr
auto fixed_width_scale(S
const& s)
37 return cnl::fixed_width_scale<Digits, Radix, S>()(s);
41 template<
int Digits,
int Radix,
typename Composite>
42 requires is_composite_v<Composite>
43 struct fixed_width_scale<
44 Digits, Radix, Composite> {
45 [[nodiscard]] constexpr
auto operator()(Composite
const& s)
const
47 return _impl::from_rep<Composite>(
48 _impl::fixed_width_scale<Digits, Radix>(_impl::to_rep(s)));
53 #endif // CNL_IMPL_NUM_TRAITS_FIXED_WIDTH_SCALE_H