Appearance
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
| Function | Type | Use it for |
|---|---|---|
abs | Int -> Int | Absolute value |
negate | Int -> Int | Flip the sign |
sign | Int -> Int | Collapse a number to -1, 0, or 1 |
isEven | Int -> Bool | Check parity |
isOdd | Int -> Bool | Check oddness |
square | Int -> Int | Multiply a number by itself |
clamp | Int -> Int -> Int -> Int | Restrict a number to a range |
between | Int -> Int -> Int -> Bool | Check whether a number lies in a range |
divides | Int -> Int -> Bool | Check exact divisibility |
gcd | Int -> Int -> Int | Greatest common divisor |
lcm | Int -> Int -> Int | Least common multiple |
pow | Int -> Int -> Int | Integer exponentiation |
digits | Int -> List Int | Break an integer into decimal digits |
fromDigits | List Int -> Int | Rebuild an integer from decimal digits |
isPrime | Int -> Bool | Primality 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 nsign
Returns the sign of an integer as -1, 0, or 1.
aivi
aivi
use aivi.math (sign)
type Int -> Int
func direction = velocity =>
sign velocityisEven
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 numbersisOdd
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 numberssquare
Multiplies an integer by itself.
aivi
aivi
use aivi.math (square)
type Int -> Int
func areaOfSquare = side =>
square sideclamp
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 rawbetween
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 agedivides
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