Iros
 
Loading...
Searching...
No Matches
fixed_unsigned.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/types/prelude.h"
7
8namespace di::math {
15template<usize bits>
16requires(bits % sizeof(bigint::StorageType) == 0)
18private:
19 constexpr static usize word_count = bits / sizeof(bigint::StorageType) / 8;
20
22
23public:
24 FixedUnsigned() = default;
25
26 constexpr FixedUnsigned(bigint::StorageType value) { m_storage[0] = value; }
27
28 constexpr auto operator/(FixedUnsigned const& divisor) const -> FixedUnsigned {
29 auto division_result = FixedUnsigned();
30 auto modulo_result = FixedUnsigned();
31 Ops::div_mod(this->span(), divisor.span(), division_result.span(), modulo_result.span());
32 return division_result;
33 }
34
35 constexpr auto operator%(FixedUnsigned const& divisor) const -> FixedUnsigned {
36 auto division_result = FixedUnsigned();
37 auto modulo_result = FixedUnsigned();
38 Ops::div_mod(this->span(), divisor.span(), division_result.span(), modulo_result.span());
39 return modulo_result;
40 }
41
42private:
43 constexpr friend auto operator==(FixedUnsigned const& a, FixedUnsigned const& b) -> bool {
44 return Ops::compare(a.span(), b.span()) == 0;
45 }
46
47 constexpr friend auto operator<=>(FixedUnsigned const& a, FixedUnsigned const& b) {
48 return Ops::compare(a.span(), b.span());
49 }
50
51 constexpr auto span() { return m_storage.span(); }
52 constexpr auto span() const { return m_storage.span(); }
53
55};
56
59}
60
61namespace di {
64using math::u256;
65}
A fixed-width unsigned integer.
Definition fixed_unsigned.h:17
constexpr friend auto operator<=>(FixedUnsigned const &a, FixedUnsigned const &b)
Definition fixed_unsigned.h:47
constexpr auto operator/(FixedUnsigned const &divisor) const -> FixedUnsigned
Definition fixed_unsigned.h:28
constexpr friend auto operator==(FixedUnsigned const &a, FixedUnsigned const &b) -> bool
Definition fixed_unsigned.h:43
constexpr auto operator%(FixedUnsigned const &divisor) const -> FixedUnsigned
Definition fixed_unsigned.h:35
constexpr FixedUnsigned(bigint::StorageType value)
Definition fixed_unsigned.h:26
unsigned long StorageType
Definition fixed_ops.h:18
Definition abs.h:10
FixedUnsigned< 128 > u128_fallback
Definition fixed_unsigned.h:57
FixedUnsigned< 256 > u256
Definition fixed_unsigned.h:58
size_t usize
Definition integers.h:33
Definition zstring_parser.h:9
Definition fixed_ops.h:21
static constexpr auto compare(Span< StorageType const, words > lhs, Span< StorageType const, words > rhs) -> strong_ordering
Definition fixed_ops.h:44
static constexpr void div_mod(Span< StorageType const, words > dividend, Span< StorageType const, words > divisor, Span< StorageType, words > quotient, Span< StorageType, words > remainder)
Definition fixed_ops.h:94
Definition span_fixed_size.h:37