Skip to content

aivi.math

Integer arithmetic utilities. Provides common numeric helpers including absolute value, sign detection, parity tests, clamping, and divisibility.

aivi
use aivi.math (
    abs
    negate
    sign
    isEven
    isOdd
    square
    clamp
    between
    divides
    gcd
    lcm
    pow
    digits
    fromDigits
    isPrime
)

At a glance

FunctionTypeUse it for
absInt -> IntAbsolute value
negateInt -> IntFlip the sign
signInt -> IntCollapse a number to -1, 0, or 1
isEvenInt -> BoolCheck parity
isOddInt -> BoolCheck oddness
squareInt -> IntMultiply a number by itself
clampInt -> Int -> Int -> IntRestrict a number to a range
betweenInt -> Int -> Int -> BoolCheck whether a number lies in a range
dividesInt -> Int -> BoolCheck exact divisibility
gcdInt -> Int -> IntGreatest common divisor
lcmInt -> Int -> IntLeast common multiple
powInt -> Int -> IntInteger exponentiation
digitsInt -> List IntBreak an integer into decimal digits
fromDigitsList Int -> IntRebuild an integer from decimal digits
isPrimeInt -> BoolPrimality test

The detailed sections below focus on the most common helpers first. The table above is the full currently exported surface for aivi.math.


abs

Returns the absolute value of an integer.

aivi
aivi
use aivi.math (abs)

type Int -> Int -> Int
func distance = a b =>
    abs (a - b)

negate

Negates an integer: negate n is equivalent to 0 - n.

aivi
aivi
use aivi.math (negate)

type Int -> Int
func flipSign = n =>
    negate n

sign

Returns the sign of an integer as -1, 0, or 1.

aivi
aivi
use aivi.math (sign)

type Int -> Int
func direction = velocity =>
    sign velocity

isEven

Returns True if the integer is divisible by 2.

aivi
aivi
use aivi.list (filter)

use aivi.math (isEven)

type List Int -> List Int
func evensOnly = numbers =>
    filter isEven numbers

isOdd

Returns True if the integer is not divisible by 2.

aivi
aivi
use aivi.list (filter)

use aivi.math (isOdd)

type List Int -> List Int
func oddsOnly = numbers =>
    filter isOdd numbers

square

Multiplies an integer by itself.

aivi
aivi
use aivi.math (square)

type Int -> Int
func areaOfSquare = side =>
    square side

clamp

Constrains a value to lie within [low, high]. If n < low, returns low; if n > high, returns high; otherwise returns n.

aivi
aivi
use aivi.math (clamp)

type Int -> Int
func normalizedVolume = raw =>
    clamp 0 100 raw

between

Returns True if n is within the inclusive range [low, high].

aivi
aivi
use aivi.math (between)

type Int -> Bool
func isValidAge = age =>
    between 0 150 age

divides

Returns True if divisor evenly divides n (i.e. n % divisor == 0).

aivi
aivi
use aivi.math (divides)

type Int -> Bool
func isMultipleOfThree = n =>
    divides 3 n

(c) 2026 by Andreas Herd