7 #if !defined(CNL_IMPL_ELASTIC_INTEGER_H)
8 #define CNL_IMPL_ELASTIC_INTEGER_H
10 #include "../num_traits/from_rep.h"
11 #include "../num_traits/rep_of.h"
12 #include "../num_traits/scale.h"
13 #include "../num_traits/to_rep.h"
14 #include "definition.h"
16 #include <type_traits>
20 template<
int ShiftDigits,
int ScaleRadix,
int ScalarDigits,
class ScalarNarrowest>
21 requires(0 <= ShiftDigits)
struct scale<
22 ShiftDigits, ScaleRadix,
elastic_integer<ScalarDigits, ScalarNarrowest>> {
23 [[nodiscard]] constexpr
auto operator()(
24 elastic_integer<ScalarDigits, ScalarNarrowest>
const& s)
const
25 -> elastic_integer<ShiftDigits + ScalarDigits, ScalarNarrowest>
27 using result_type = elastic_integer<ShiftDigits + ScalarDigits, ScalarNarrowest>;
28 using result_rep = _impl::rep_of_t<result_type>;
29 return _impl::from_rep<result_type>(
30 scale<ShiftDigits, ScaleRadix, result_rep>()(_impl::to_rep(s)));
34 template<
int ShiftDigits,
int ScalarDigits,
class ScalarNarrowest>
35 requires(ShiftDigits < 0) struct scale<
37 [[nodiscard]] constexpr
auto operator()(
38 elastic_integer<ScalarDigits, ScalarNarrowest>
const& s)
const
39 -> elastic_integer<ShiftDigits + ScalarDigits, ScalarNarrowest>
42 using divisor_rep = _impl::rep_of_t<divisor_type>;
43 return _impl::to_rep(s) / (divisor_rep{1} << -ShiftDigits);
48 #endif // CNL_IMPL_ELASTIC_INTEGER_H