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<u16>

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

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

Syntax: wrapping<u16>

Category#

arithmetic

Examples#

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

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

# =============================================================================
# wrapping<u16> — Unsigned 16-bit modular-word arithmetic and bit-pattern edges.
# =============================================================================
#
# What this teaches:
#   • Modular word contract — `wrapping<u16>` wraps on overflow for add, sub, mul, neg, and shifts.
#   • Edge cases — Max + 1, zero - 1, and shifts beyond bit width demonstrate wrapping behavior.
#
# Common mistakes:
#   • Assuming modular words trap on overflow like checked int does.
#
# See also: int, ¬, ⇐, ⇒
# =============================================================================

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

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

Expected output:

0
65535
65534
65535
65535
0
0
true
0
65535
1
1
0
0
0