Dedekind 0.0.0
A structuralist C++23 Module Library
Loading...
Searching...
No Matches
dedekind::sets::SignedExtensionalCardinal< S > Struct Template Referenceexport

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>

Public Member Functions

template<std::integral I>
constexpr SignedExtensionalCardinal (I v) noexcept
 Construction from any integral source, modulo 2^w.
constexpr bool negative () const noexcept
 Is the value negative?
constexpr magnitude_type magnitude () const noexcept
 |value| as an unsigned word (exact, also for min).
constexpr operator std::size_t () const noexcept
 Explicit projection to std::size_t — the magnitude (sign is dropped). Sibling to ExtensionalCardinal::operator std::size_t() ; used at the same call sites in :sequences:path 's helpers.
constexpr SignedExtensionalCardinal operator- () const noexcept
 The additive inverse in ℤ/2^w (-min wraps to min).
template<std::signed_integral Target>
constexpr operator Target () const noexcept
 Explicit conversion to a signed integral type (modular, like the carrier). Used by the IR-fixture showcases to extract a compile-time-known rational's numerator as a concrete machine integer for the emitted ret i64 ... witness.

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.

Detailed Description

template<typename S = std::ptrdiff_t>
requires std::signed_integral<S> && IsWrappingWord<std::make_unsigned_t<S>>
struct dedekind::sets::SignedExtensionalCardinal< S >

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.

Template Parameters
SThe 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.

The documentation for this struct was generated from the following file: