Skip to content

Math

Static methods on the Math module.

Methods

MethodReturnsDescription
Math.abs(x)intAbsolute value
Math.max(a, b)intMaximum
Math.min(a, b)intMinimum
Math.pow(base, exp)intPower
Math.sqrt(x)floatSquare root
Math.clamp(x, lo, hi)intClamp to range
Math.ceil(x)intRound up
Math.floor(x)intRound down
Math.round(x)intRound to nearest
Math.sign(x)int-1, 0, or 1
Math.lerp(a, b, t)floatLinear interpolation
Math.map_range(x, a1, a2, b1, b2)floatMap between ranges
Math.log(x)floatNatural log
Math.log10(x)floatBase-10 log
Math.exp(x)floate^x
Math.random()intRandom integer

Examples

wyn
println(Math.abs(-5).to_string())       // 5
println(Math.max(10, 20).to_string())   // 20
println(Math.pow(2, 8).to_string())     // 256
println(Math.sqrt(16).to_string())      // 4.0
println(Math.clamp(150, 0, 100).to_string()) // 100

See Also

MIT License