Skip to main content
Standard math library.
import math

Functions

FunctionDescriptionExampleResult
math.sqrt(x)Square rootmath.sqrt(144)12
math.abs(x)Absolute valuemath.abs(-5)5
math.ceil(x)Round upmath.ceil(3.2)4
math.floor(x)Round downmath.floor(3.8)3
math.round(x)Round to nearestmath.round(3.5)4
math.pow(x, y)Powermath.pow(2, 10)1024
math.min(a, b)Minimummath.min(3, 7)3
math.max(a, b)Maximummath.max(3, 7)7
math.random()Random 0.0–1.0math.random()0.73...
math.random_int(min, max)Random integermath.random_int(1, 10)7
math.pi()Pi constantmath.pi()3.14159...
math.sin(x)Sine (radians)math.sin(1.57)~1.0
math.cos(x)Cosine (radians)math.cos(0)1.0
math.tan(x)Tangent (radians)math.tan(0.785)~1.0
math.log(x)Natural logmath.log(2.718)~1.0
math.log10(x)Base-10 logmath.log10(100)2.0

Examples

import math

# Distance between two points
function distance(x1, y1, x2, y2)
    dx = x2 - x1
    dy = y2 - y1
    return math.sqrt(dx * dx + dy * dy)

print(distance(0, 0, 3, 4))
# Output: 5

# Random dice roll
roll = math.random_int(1, 6)
print("You rolled: {roll}")

Compile Flag

cargo build --release --no-default-features --features mod_math