namespaces

math

Numeric helpers for rounding, clamping, and comparing numbers.

The math namespace provides numeric helpers that work across integer, float, and decimal values. Individual numbers also carry their own methods (see Types). Use math for the standalone helpers like clamp.

When to use

Reach for math to constrain or round a number in a route, for example clamping a page size or rounding a computed total.

Operations

marreta
size = math.clamp(requested, min: 1, max: 100)
NameSignatureSummary
math.roundmath.round(value, places: N)Rounds to the given places.
math.ceilmath.ceil(value)Rounds up to an integer.
math.floormath.floor(value)Rounds down to an integer.
math.absmath.abs(value)Returns the absolute value.
math.clampmath.clamp(value, min: N, max: N)Constrains a number to a range.
math.minmath.min(left, right)Returns the smaller number.
math.maxmath.max(left, right)Returns the larger number.