39 inline constexpr
operator double()
const {
return static_cast<double>(value);}
40 inline constexpr
operator bool()
const {
return static_cast<bool>(value);}
41 uint33_t& operator=(
const uint64_t& i) { value = i;
return *
this;}
42 constexpr
static uint33_t max_value() {
return {0x1ffffffff};};
43 constexpr
static uint33_t half_max() {
return {uint33_t::max_value().value/2};}
48 inline constexpr
bool operator<(
const uint33_t& l,
const uint33_t& r) {
return l.value < r.value; }
49 inline constexpr
bool operator>(
const uint33_t& l,
const uint33_t& r) {
return r < l; }
51 inline constexpr
bool operator==(
const uint33_t& l,
const uint33_t& r) {
return l.value == r.value; }
52 inline constexpr
bool operator!=(
const uint33_t& l,
const uint33_t& r) {
return !(l == r);}
54 template<
typename Integer>
55 inline constexpr
bool operator==(
const uint33_t& l,
const Integer& r) {
return l ==
uint33_t{
static_cast<uint64_t
>(r)}; }
57 template<
typename Integer>
58 inline constexpr
bool operator!=(
const uint33_t& l,
const Integer& r) {
return !(l == r);}
60 template<
typename Integer>
61 inline constexpr
bool operator==(
const Integer& l,
const uint33_t& r) {
return r == l; }
63 template<
typename Integer>
64 inline constexpr
bool operator!=(
const Integer& l,
const uint33_t& r) {
return !(l == r);}
66 namespace test_variables
68 constexpr
uint33_t max_val{0x1ffffffff};
70 #if defined(__clang__)
71 #pragma clang diagnostic push
72 #pragma clang diagnostic ignored "-Woverflow"
73 #elif defined(__GNUC__) || defined(__GNUG__)
74 #pragma GCC diagnostic push
75 #pragma GCC diagnostic ignored "-Woverflow"
78 constexpr
uint33_t from_max_u64{std::numeric_limits<uint64_t>::max()};
79 #if defined(__clang__)
80 #pragma clang diagnostic pop
81 #elif defined(__GNUC__) || defined(__GNUG__)
82 #pragma GCC diagnostic pop
85 constexpr
uint33_t big_val{0x1fffffffc};
92 static_assert(four.value == 4,
"value representation");
93 static_assert(two.value == 2,
"value representation");
94 static_assert(zero.value == 0,
"value representation");
95 static_assert(max_val.value == 0x1ffffffff,
"value representation");
96 static_assert(from_max_u64.value == 0x1ffffffff,
"value representation");
98 static_assert((
double)four == 4.0,
"implicit double operator");
99 static_assert((
bool)four,
"implicit bool operator - positive gives true");
100 static_assert(!!four,
"implicit bool operator - positive gives true");
101 static_assert(!((
bool)zero),
"implicit bool operator - zero gives false");
102 static_assert(!zero,
"implicit bool operator - zero gives false");
104 static_assert(three + four == seven,
"addition");
106 static_assert(max_val + four == three,
"addition");
107 static_assert(four + max_val == three,
"addition");
109 static_assert(seven - four == three,
"substraction");
110 static_assert(three - seven == (max_val - three),
"substraction");
111 static_assert(three - seven == (zero - four),
"substraction");
113 static_assert(three - big_val == seven,
"substraction");
116 static_assert(three == three,
"equality comparison");
117 static_assert(!(three == four),
"equality comparison");
118 static_assert(three != four,
"equality comparison");
119 static_assert(!(three != three),
"equality comparison");
120 static_assert(from_max_u64 == max_val,
"equality comparison");
123 static_assert(three == 3,
"int equality comparison");
124 static_assert(three != 4,
"int equality comparison");
125 static_assert(!(three == 4),
"int equality comparison");
127 static_assert(three < four,
"lt comparison");
128 static_assert(!(three < three),
"lt comparison");
129 static_assert(!(three < two),
"lt comparison");
131 static_assert(four > three,
"gt comparison");
132 static_assert(!(three > three),
"gt comparison");
133 static_assert(!(two > three),
"gt comparison");
144 assert(x == four &&
"int assignment");