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

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

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

Syntax: wrapping<u8>

Category#

arithmetic

Examples#

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

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

# =============================================================================
# wrapping<u8> — Unsigned 8-bit modular-word arithmetic and bit-pattern edges.
# =============================================================================
#
# What this teaches:
#   • Modular word contract — `wrapping<u8>` wraps on 8-bit overflow; edge cases wrap predictably.
#   • Bit-pattern edges — Shifting 1 ⇐ 8 wraps to 0; negating 1 wraps to 255.
#
# Common mistakes:
#   • Expecting division or remainder by zero to produce a value rather than fail.
#
# See also: int, ¬, ⇐, ⇒
# =============================================================================

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

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

Expected output:

0
255
254
255
255
0
0
true
0
255
1
1
0
0
0