Skip to content

aivi.math ​

Pure integer helpers for sign, bounds, divisibility, and small whole-number calculations.

aivi
use aivi.math (
    abs
    negate
    sign
    isEven
    isOdd
    square
    clamp
    between
    divides
    gcd
    lcm
    pow
)
FunctionTypeBehavior
absInt -> IntAbsolute value
negateInt -> IntFlip the sign
signInt -> IntReturn -1, 0, or 1
isEvenInt -> BoolTest divisibility by two
isOddInt -> BoolTest non-divisibility by two
squareInt -> IntMultiply a value by itself
clampInt -> Int -> Int -> IntRestrict a value to inclusive bounds
betweenInt -> Int -> Int -> BoolTest inclusive bounds
dividesInt -> Int -> BoolTest exact divisibility; zero divides only zero
gcdInt -> Int -> IntGreatest common divisor
lcmInt -> Int -> IntLeast common multiple; returns zero when either input is zero
powInt -> Int -> IntNon-negative integer exponentiation; negative exponents return zero

Int arithmetic has the same fixed-width overflow behavior as ordinary language arithmetic.

aivi
use aivi.math (
    between
    gcd
    isEven
)

value aligned : Bool = isEven 42
value divisor : Int = gcd 84 30
value validPercent : Bool = between 0 100 75

(c) 2026 by Andreas Herd