Nanyx

math

Numeric utility functions

The math module provides common numeric and floating-point operations.

Functions that work on any numeric type are generic over the Num(a) context; int and float are its built-in instances, so these functions accept either without conversion. Functions that only make sense for floating-point values take float directly.

abs

math.abs: [Num(a)] a -> a
math.abs(-42)
-- 42

min

math.min: [Num(a)] (a, a) -> a
math.min(3, 7)
-- 3

max

math.max: [Num(a)] (a, a) -> a
math.max(3, 7)
-- 7

clamp

math.clamp: [Num(a)] (a, min: a, max: a) -> a
math.clamp(120, min = 0, max = 100)
-- 100

sqrt

math.sqrt: float -> float
math.sqrt(81.0)
-- 9.0

pow

math.pow: [Num(a)] (a, int) -> a
math.pow(2, 8)
-- 256

floor

math.floor: float -> int
math.floor(3.9)
-- 3

ceil

math.ceil: float -> int
math.ceil(3.1)
-- 4

round

math.round: float -> int
math.round(3.5)
-- 4