Standard Library: Math functions
abs
[abs: num]
→ int | float
Prints the absolute value of num.
Parameters
num ← int | float
The input number.
Errors
Raises an error if num is an integer and the absolute value overflows.
add
[add: lhs; rhs]
→ any
Adds two values and prints the sum.
Parameters
lhs ← any
The left-hand operand of the addition.
rhs ← any
The right-hand operand of the addition.
clamp
[clamp: value; a; b]
Prints value clamped to the inclusive range between a and b.
ceil
[ceil: val]
→ int
Prints the smallest integer that is greater than or equal to val.
Parameters
val ← float
The input number.
div
[div: lhs; rhs]
→ any
Divides two values and prints the quotient.
Parameters
lhs ← any
The left-hand operand (dividend).
rhs ← any
The right-hand operand (divisor).
floor
[floor: val]
→ int
Prints the largest integer that is less than or equal to val.
Parameters
val ← float
The input number.
frac
[frac: val]
→ float
Prints the fractional part of val.
Parameters
val ← float
The input number.
max
[max: values+]
→ any
Returns the largest value in values.
Any elements of type list in values will be expanded to their individual elements
before the maximum value is calculated.
Parameters
values ← any+
The input values.
Examples
# Arguments can be single values
[max: 3; 2 |> assert-eq: 3]
# Lists are treated as their individual elements
[max: (3; 2) |> assert-eq: 3]
# Even alongside single values, lists are still expanded!
[max: 3; (4; -2; 0; 10); 6 |> assert-eq: 10]
min
[min: values+]
→ any
Returns the smallest value in values.
Any elements of type list in values will be expanded to their individual elements
before the minimum value is calculated.
Parameters
values ← any+
The input values.
Examples
# Arguments can be single values
[min: 3; 2 |> assert-eq: 2]
# Lists are treated as their individual elements
[min: (3; 2) |> assert-eq: 2]
# Even alongside single values, lists are still expanded!
[min: 3; (4; -2; 0; 10); 6 |> assert-eq: -2]
mod
[mod: lhs; rhs]
→ any
Gets the modulus of two values.
Parameters
lhs ← any
The left-hand operand (dividend).
rhs ← any
The right-hand operand (divisor).
mul
[mul: lhs; rhs]
→ any
Multiplies two values and prints the product.
Parameters
lhs ← any
The left-hand operand.
rhs ← any <br.>
The right-hand operand.
mul-add
[mul-add: lhs; rhs; add]
→ any
Multiplies two values, then adds another value to the result.
Parameters
lhs ← any
The left-hand operand of the multiplication.
rhs ← any
The right-hand operand of the multiplication.
add ← any
The value to add to the product.
neg
[neg: val]
→ any
Negates a value and prints it.
Parameters
val ← any
The input value.
recip
[recip: n]
→ any
Gets the reciprocal of a value.
sub
[sub: lhs; rhs]
→ any
Prints the difference between two values.
Parameters
lhs ← any
The left-hand operand of the subtraction.
rhs ← any
The right-hand side of the subtraction.
sin
[sin: x]
→ float
Calculates the sine of x.
Parameters
x ← float
The input value, in radians.
cos
[cos: x]
→ float
Calculates the cosine of x.
Parameters
x ← float
The input value, in radians.
tan
[tan: x]
→ float
Calculates the tangent of x.
Parameters
x ← float
The input value, in radians.
asin
[asin: x]
→ float
Calculates the arcsine (in radians) of x.
Parameters
x ← float
The input sine value.
acos
[acos: x]
→ float
Calculates the arccosine (in radians) of x.
Parameters
x ← float
The input cosine value.
atan
[atan: x]
→ float
Calculates the arctangent (in radians) of x.
Parameters
x ← float
The input tangent value.
atan2
[atan2: y; x]
→ float
Calculates the four-quadrant arctangent (in radians) of \(\frac{y}{x}\).
Returns 0 if x or y is 0.
Parameters
y ← float
The input tangent's numerator.
x ← float
The input tangent's denominator.
sqrt
[sqrt: x]
→ float
Calculates the square root of x.
Parameters
x ← int | float
The input value.
pow
[pow: x; y]
→ int | float
Calculates \(x^y\) and prints the result. Both x and y can be int or float.
Parameters
x ← int | float
The base number.
y ← int | flaot
The exponent to raise x to.
Errors
Raises an overflow error if a x is an int and x ^ y causes an overflow.