|
Dedekind 0.0.0
A structuralist C++23 Module Library
|
Signed one-word integer: two's complement in the signed word S.
More...
Classes | |
| struct | CheckedResult |
| A wrapped result and whether the exact result overflowed. More... | |
Public Types | |
| using | signed_type = S |
| using | word_type = std::make_unsigned_t<S> |
| using | magnitude_type = ExtensionalCardinal<word_type> |
Static Public Member Functions | |
| static constexpr CheckedResult | checked_add (const SignedExtensionalCardinal &lhs, const SignedExtensionalCardinal &rhs) noexcept |
| static constexpr CheckedResult | checked_sub (const SignedExtensionalCardinal &lhs, const SignedExtensionalCardinal &rhs) noexcept |
| static constexpr CheckedResult | checked_mul (const SignedExtensionalCardinal &lhs, const SignedExtensionalCardinal &rhs) noexcept |
Public Attributes | |
| signed_type | value {} |
Friends | |
| constexpr friend bool | operator== (const SignedExtensionalCardinal &, const SignedExtensionalCardinal &)=default |
| constexpr friend std::strong_ordering | operator<=> (const SignedExtensionalCardinal &lhs, const SignedExtensionalCardinal &rhs) noexcept |
| template<std::integral T> | |
| constexpr friend bool | operator== (const SignedExtensionalCardinal &lhs, T rhs) noexcept |
Heterogeneous comparison with built-in integrals, exact across signedness (compared in 128 bits). Without it, SEC == int is ambiguous between the SEC and SignedCardinality overloads, each one user-defined conversion away. | |
| template<std::integral T> | |
| constexpr friend bool | operator== (T lhs, const SignedExtensionalCardinal &rhs) noexcept |
| template<std::integral T> | |
| constexpr friend std::strong_ordering | operator<=> (const SignedExtensionalCardinal &lhs, T rhs) noexcept |
| template<std::integral T> | |
| constexpr friend std::strong_ordering | operator<=> (T lhs, const SignedExtensionalCardinal &rhs) noexcept |
| constexpr friend SignedExtensionalCardinal | operator+ (const SignedExtensionalCardinal &lhs, const SignedExtensionalCardinal &rhs) noexcept |
| constexpr friend SignedExtensionalCardinal | operator- (const SignedExtensionalCardinal &lhs, const SignedExtensionalCardinal &rhs) noexcept |
| constexpr friend SignedExtensionalCardinal | operator* (const SignedExtensionalCardinal &lhs, const SignedExtensionalCardinal &rhs) noexcept |
| constexpr friend SignedExtensionalCardinal | operator/ (const SignedExtensionalCardinal &lhs, const SignedExtensionalCardinal &rhs) noexcept |
Division truncating toward zero (C++ semantics). Division by zero yields zero by convention; min / -1 wraps to min. | |
| constexpr friend SignedExtensionalCardinal | operator% (const SignedExtensionalCardinal &lhs, const SignedExtensionalCardinal &rhs) noexcept |
Remainder with the sign of the dividend (C++ semantics: a == (a / b) * b + a % b). Modulo zero yields lhs. | |
Signed one-word integer: two's complement in the signed word S.
One structural field, value, of type S. Arithmetic runs through the overflow builtins on that type, which yield the wrapped result, so the carrier is exactly the residue ring ℤ/2^w read in the signed range [-2^(w-1), 2^(w-1)-1]: a genuine commutative ring and cyclic group, which the registrations below claim. -min wraps to min, and min / -1 is min (the ring answer), so no operation is undefined.
It satisfies IsInteger (see registrations after the numbers:integer module pulls this file), making it the signed backing carrier for fixed-width Rational<Z>. The SignedCardinality variant downstream escalates to ±ℵ_0 where this carrier wraps.
Structural on purpose: the public field makes the type usable as a non-type template parameter wherever Rational<Z> is.
| S | The signed word (default std::ptrdiff_t, the signed twin of std::size_t). Gated on being a signed built-in integer whose unsigned twin is an IsWrappingWord: the raw signed type is not a ring (overflow is UB), but this carrier's builtin-based arithmetic is exactly the ring of its unsigned twin. |