Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

modulus<u32>

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Unsigned 32-bit modular-word arithmetic and bit-pattern edges.

Syntax: wrapping<u32>

Category#

arithmetic

Examples#

radix/corpus/reference/operator-group/modulus-u32/modular-word.fab (canonical · operator-group)#

Unsigned 32-bit modular-word arithmetic and bit-pattern edges.

# =============================================================================
# wrapping<u32> — Unsigned 32-bit modular-word arithmetic and bit-pattern edges.
# =============================================================================
#
# What this teaches:
#   • Modular word contract — `wrapping<u32>` is an unsigned 32-bit word with wrapping arithmetic.
#   • Edge cases — Max + 1, zero - 1, and 1 ⇐ 32 demonstrate wrapping at the 32-bit boundary.
#
# Common mistakes:
#   • Assuming modular word division or remainder by zero returns a value instead of failing.
#
# See also: int, ¬, ⇐, ⇒
# =============================================================================

# operatores/modular-word — wrapping<u32> edge vectors
#
# MODULAR WORD CONTRACT:
#   wrapping<u32> is an unsigned 32-bit modular word. Addition, subtraction,
#   multiplication, negation, bitwise operations, and shifts use u32 wrapping.
#   Division and remainder by zero fail.

main {
    mut wrapping<u32> max ← 4294967295
    let wrapping<u32> one ← 1
    mut wrapping<u32> zero ← 0
    let u32 converted ↤ one
    let wrapping<u32> ring1 ← max + one
    print ring1
    let wrapping<u32> ring2 ← zero - one
    print ring2
    let wrapping<u32> ring3 ← max * 2
    print ring3
    let wrapping<u32> ring4 ← -one
    print ring4
    let wrapping<u32> ring5 ← ¬ zero
    print ring5
    let wrapping<u32> ring6 ← one ⇐ 32
    print ring6
    print max ⇒ 32
    print max ≻ zero
    max ↑
    zero ↓
    print max
    print zero
    let wrapping<u32> methodSum ← max.added(one)
    let wrapping<u32> methodShift ← max.shifted_left(32)
    mut wrapping<u32> methodAcc ← 0
    methodAcc.add(one)
    methodAcc.shift_left(32)
    print converted
    print methodSum
    print methodShift
    print methodAcc
    let list<wrapping<u32>> words ← [one, max]
    print words.get(1) coalesce 0 ∷ wrapping<u32>
}

Expected output:

0
4294967295
4294967294
4294967295
4294967295
0
0
true
0
4294967295
1
1
0
0
0