modulus<u64>
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Unsigned 64-bit modular-word arithmetic and bit-pattern edges.
Syntax: wrapping<u64>
Category#
arithmetic
Related#
- int
- ¬
- ⇐
- ⇒
Examples#
radix/corpus/reference/operator-group/modulus-u64/modular-word-u64.fab (canonical · operator-group)#
Unsigned 64-bit modular-word arithmetic and bit-pattern edges.
# =============================================================================
# wrapping<u64> — Unsigned 64-bit modular-word arithmetic and bit-pattern edges.
# =============================================================================
#
# What this teaches:
# • Modular word contract — `wrapping<u64>` wraps on overflow; demonstrates max + 1, zero - 1.
# • Carrier-mix equality — Conversions and arithmetic results compare by value across carriers.
#
# Common mistakes:
# • Assuming 64-bit modular words trap on overflow like checked int types.
#
# See also: int, ¬, ⇐, ⇒
# =============================================================================
# operatores/modular-word-u64 — wrapping<u64> edge vectors
#
# MODULAR WORD CONTRACT:
# wrapping<u64> is an unsigned 64-bit modular word. Addition, subtraction,
# multiplication, negation, bitwise operations, and shifts use u64 wrapping.
# Division and remainder by zero fail.
main {
mut wrapping<u64> max ← 18446744073709551615
let wrapping<u64> one ← 1
mut wrapping<u64> zero ← 0
let u64 converted ↤ one
let wrapping<u64> ring1 ← max + one
print ring1
let wrapping<u64> ring2 ← zero - one
print ring2
let wrapping<u64> ring3 ← max * 2
print ring3
let wrapping<u64> ring4 ← -one
print ring4
let wrapping<u64> ring5 ← ¬ zero
print ring5
let wrapping<u64> ring6 ← one ⇐ 64
print ring6
print max ⇒ 64
print max ≻ zero
# Carrier-mix equality: conversions and arithmetic results compare by
# value against literals (review regression).
let wrapping<u64> uno ↤ 1
print one ≡ uno
print one ≡ one + 0
max ↑
zero ↓
print max
print zero
let wrapping<u64> methodSum ← max.added(one)
let wrapping<u64> methodShift ← max.shifted_left(64)
mut wrapping<u64> methodAcc ← 0
methodAcc.add(one)
methodAcc.shift_left(64)
print converted
print methodSum
print methodShift
print methodAcc
let list<wrapping<u64>> words ← [one, max]
print words.get(1) coalesce 0 ∷ wrapping<u64>
mut list<wrapping<u64>> sorted ← [18446744073709551615, 3, 10, 2]
sorted.sort()
print sorted
}Expected output:
0
18446744073709551615
18446744073709551614
18446744073709551615
18446744073709551615
0
0
true
true
true
0
18446744073709551615
1
1
0
0
0
[2, 3, 10, 18446744073709551615]