10 #if !defined(CNL_IMPL_SCALED_INTEGER_OPERATORS_H)
11 #define CNL_IMPL_SCALED_INTEGER_OPERATORS_H
13 #include "../narrow_cast.h"
14 #include "../scaled/power.h"
15 #include "definition.h"
26 _impl::comparison_op Operator,
27 typename LhsRep,
int LhsExponent,
28 typename RhsRep,
int RhsExponent,
30 requires(LhsExponent < RhsExponent)
struct custom_operator<
34 static constexpr
int shiftage = RhsExponent - LhsExponent;
35 using lhs_type = scaled_integer<LhsRep, power<LhsExponent, Radix>>;
37 decltype(std::declval<RhsRep>() << constant<shiftage>()),
38 power<LhsExponent, Radix>>;
40 [[nodiscard]] constexpr
auto operator()(
42 scaled_integer<RhsRep, power<RhsExponent, Radix>>
const& rhs)
const
44 return _impl::operate<Operator>{}(lhs_type{lhs}, rhs_type{rhs});
49 _impl::comparison_op Operator,
50 typename LhsRep,
int LhsExponent,
51 typename RhsRep,
int RhsExponent,
53 requires(RhsExponent < LhsExponent)
struct custom_operator<
57 static constexpr
int shiftage = LhsExponent - RhsExponent;
59 decltype(std::declval<LhsRep>() << constant<shiftage>()),
60 power<RhsExponent, Radix>>;
61 using rhs_type = scaled_integer<RhsRep, power<RhsExponent, Radix>>;
63 [[nodiscard]] constexpr
auto operator()(
65 scaled_integer<RhsRep, power<RhsExponent, Radix>>
const& rhs)
const
67 return _impl::operate<Operator>{}(lhs_type{lhs}, rhs_type{rhs});
75 template<
typename LhsRep,
int LhsExponent,
int LhsRadix, CNL_IMPL_CONSTANT_VALUE_TYPE RhsValue>
76 struct custom_operator<
78 op_value<scaled_integer<LhsRep, power<LhsExponent, LhsRadix>>>,
79 op_value<constant<RhsValue>>> {
80 using result_type = scaled_integer<LhsRep, power<LhsExponent + _impl::narrow_cast<int>(RhsValue), LhsRadix>>;
81 [[nodiscard]] constexpr
auto operator()(
83 constant<RhsValue>)
const
85 return _impl::from_rep<result_type>(_impl::to_rep(lhs));
90 template<
typename LhsRep,
int LhsExponent,
int LhsRadix, CNL_IMPL_CONSTANT_VALUE_TYPE RhsValue>
91 struct custom_operator<
92 _impl::shift_right_op,
93 op_value<scaled_integer<LhsRep, power<LhsExponent, LhsRadix>>>,
94 op_value<constant<RhsValue>>> {
95 using result_type =
scaled_integer<LhsRep, power<LhsExponent - _impl::narrow_cast<int>(RhsValue), LhsRadix>>;
96 [[nodiscard]] constexpr
auto operator()(
98 constant<RhsValue>)
const
100 return _impl::from_rep<result_type>(_impl::to_rep(lhs));
105 #endif // CNL_IMPL_SCALED_INTEGER_OPERATORS_H