7 #if !defined(CNL_IMPL_DUPLEX_INTEGER_CTORS_H)
8 #define CNL_IMPL_DUPLEX_INTEGER_CTORS_H
10 #include "../power_value.h"
11 #include "definition.h"
12 #include "operators.h"
21 template<
typename Lower,
typename Integer>
22 requires(digits_v<Lower> >= digits_v<Integer>)
23 [[nodiscard]] constexpr
auto calculate_lower(Integer
const& input) -> Lower
28 template<
typename Lower,
typename Integer>
29 requires(digits_v<Lower> < digits_v<Integer>)
30 [[nodiscard]] constexpr
auto calculate_lower(Integer
const& input) -> Lower
36 template<
typename Upper,
typename Lower,
typename Integer>
37 requires(digits_v<Lower> >= digits_v<Integer>)
38 [[nodiscard]] constexpr
auto calculate_upper(Integer
const& input) -> Upper
43 return static_cast<Upper
>((input >> (digits_v<Integer> - 1)) >> 1);
46 template<
typename Upper,
typename Lower,
typename Integer>
47 requires(digits_v<Lower> < digits_v<Integer>)
48 [[nodiscard]] constexpr
auto calculate_upper(Integer
const& input) -> Upper
50 return sensible_right_shift<Upper>(input, digits_v<Lower>);
53 template<
typename Upper,
typename Lower>
54 constexpr duplex_integer<Upper, Lower>::duplex_integer(
55 upper_type
const& u, lower_type
const& l)
61 template<
typename Upper,
typename Lower>
62 template<
integer Number>
63 constexpr duplex_integer<Upper, Lower>::duplex_integer(Number
const& n)
64 : _upper(calculate_upper<Upper, Lower>(n))
65 , _lower(calculate_lower<Lower>(n))
72 template<
typename Upper,
typename Lower>
73 template<std::
floating_po
int Number>
74 constexpr duplex_integer<Upper, Lower>::duplex_integer(Number
const& n)
75 : _upper(Upper(n / power_value<Number, lower_width, 2>()))
76 , _lower(Lower(
std::
fmod(n, power_value<Number, lower_width, 2>())))
82 #endif // CNL_IMPL_DUPLEX_INTEGER_CTORS_H