API Reference › Math
namespace

Math

Deterministic fixed-point math. Every function is computed in Q16.16 with plain integer arithmetic, so results are bit-identical on every platform and every run — the same guarantee the rest of the runtime gives. Arguments are positional. Given a float or double argument, the same functions compute in that type instead (using the platform's math library) and return it — floor, ceil and round included, which return an int only for fixed. sign returns an int either way. trunc and atan exist only for floats.

Math.min(a, b) -> intThe smaller of two values.Math.max(a, b) -> intThe larger of two values.Math.abs(x) -> intThe magnitude of a value, dropping its sign.Math.clamp(v, lo, hi) -> intConstrain a value to the range [lo, hi].Math.sign(x) -> intThe sign of a value as -1, 0, or 1.Math.floor(x) -> intRound a fixed value down to the nearest whole int.Math.ceil(x) -> intRound a fixed value up to the nearest whole int.Math.round(x) -> intRound a fixed value to the nearest whole int.Math.lerp(a, b, t) -> fixedBlend between two values by a 0..1 amount.Math.inverse_lerp(a, b, v) -> fixedFind where a value sits between two endpoints as a 0..1 fraction.Math.remap(v, in0, in1, out0, out1) -> fixedRescale a value from one range into another.Math.sqrt(x) -> fixedThe square root of a fixed value.Math.sin(radians) -> fixedSine of an angle in radians.Math.cos(radians) -> fixedCosine of an angle in radians.Math.tan(radians) -> fixedTangent of an angle in radians.Math.hypot(x, y) -> fixedLength of the vector (x, y).Math.dist(x0, y0, x1, y1) -> fixedDistance between two points.Math.dist2(x0, y0, x1, y1) -> fixedSquared distance between two points.Math.deg_to_rad(degrees) -> fixedConvert degrees to radians.Math.rad_to_deg(radians) -> fixedConvert radians to degrees.Math.posmod(a, m) -> intModulo that is always non-negative.Math.wrap(v, lo, hi) -> intWrap a value into the range [lo, hi).Math.ping_pong(t, len) -> intBounce a counter back and forth in [0, len].Math.snapped(v, step) -> fixedRound a value to the nearest multiple of step.Math.move_toward(from, to, delta) -> fixedStep from one value toward another by at most delta.Math.smoothstep(e0, e1, x) -> fixedA smooth 0..1 ramp between two edges.Math.atan2(y, x) -> fixedThe angle of the vector (x, y), in radians.Math.asin(x) -> fixedThe arcsine of a value, in radians.Math.acos(x) -> fixedThe arccosine of a value, in radians.Math.exp(x) -> fixede raised to the power x.Math.log(x) -> fixedThe natural logarithm of x.Math.pow(base, exp) -> fixedbase raised to a fixed exponent.
← All symbols