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
)abs
Returns the absolute value of an integer.
aivi
abs : Int -> Intaivi
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
negate : Int -> Intaivi
use aivi.math (negate)
type Int -> Int
func flipSign = n =>
negate nsign
Returns the sign of an integer as -1, 0, or 1.
aivi
sign : Int -> Intaivi
use aivi.math (sign)
type Int -> Int
func direction = velocity =>
sign velocityisEven
Returns True if the integer is divisible by 2.
aivi
isEven : Int -> Boolaivi
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
isOdd : Int -> Boolaivi
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
square : Int -> Intaivi
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
clamp : Int -> Int -> Int -> Intaivi
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
between : Int -> Int -> Int -> Boolaivi
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
divides : Int -> Int -> Boolaivi
use aivi.math (divides)
type Int -> Bool
func isMultipleOfThree = n =>
divides 3 n