math
square
Signature
math.square(value)Description
Returns the square of a number.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value | number | yes | The number to square |
Returns
| Type | Description |
|---|---|
number | value² |
Examples
math.square(3) // 9
math.square(-4) // 16cube
Signature
math.cube(value)Description
Returns the cube of a number.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value | number | yes | The number to cube |
Returns
| Type | Description |
|---|---|
number | value³ |
Examples
math.cube(3) // 27
math.cube(-2) // -8clamp
Signature
math.clamp(value, min, max)Description
Clamps a number between a minimum and maximum value.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value | number | yes | The number to clamp |
min | number | yes | The lower bound |
max | number | yes | The upper bound |
Returns
| Type | Description |
|---|---|
number | value clamped between min and max |
Examples
math.clamp(5, 0, 10) // 5
math.clamp(-5, 0, 10) // 0
math.clamp(15, 0, 10) // 10round
Signature
math.round(value, precision = 2)Description
Rounds a number to a given number of decimal places.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value | number | yes | The number to truncate |
precision | number | no | Number of decimal places. Defaults to 2 |
Returns
| Type | Description |
|---|---|
number | The rounded number |
Examples
math.truncate(1.23456) // 1.23
math.truncate(1.23456789, 4) // 1.2346
math.truncate(1.23456789, 7) // 1.2345679percentage
Signature
math.percentage(value, total)Description
Returns the percentage of value relative to total, truncated to 2 decimal places.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
value | number | yes | The partial value |
total | number | yes | The total value |
Returns
| Type | Description |
|---|---|
number | The percentage, truncated to 2 decimal places |
Examples
math.percentage(1, 4) // 25
math.percentage(1, 3) // 33.33linear
Signature
math.linear(t, initial = 0, final = 1)Description
Linearly interpolates between initial and final based on a normalized progress value t.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
t | number | yes | Normalized progress value in [0, 1] |
initial | number | no | The start value. Defaults to 0 |
final | number | no | The end value. Defaults to 1 |
Returns
| Type | Description |
|---|---|
number | Interpolated value between initial and final |
Examples
math.linear(0) // 0
math.linear(0.5) // 0.5
math.linear(1) // 1
math.linear(0.5, 0, 100) // 50
math.linear(0.5, 100, 200) // 150easeIn
Signature
math.easeIn(t, linearity = 0.5)Description
Applies an ease-in curve to a normalized value t. The curve starts slow and accelerates. linearity controls the sharpness of the curve — lower values produce a sharper ease-in.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
t | number | yes | Normalized progress value in [0, 1] |
linearity | number | no | Controls the sharpness of the curve. Defaults to 0.5 |
Returns
| Type | Description |
|---|---|
number | Eased value in [0, 1] |
Examples
math.easeIn(0) // 0
math.easeIn(0.5) // 0.25
math.easeIn(1) // 1
math.easeIn(0.5, 0.25) // sharper curveeaseOut
Signature
math.easeOut(t, linearity = 0.5)Description
Applies an ease-out curve to a normalized value t. The curve starts fast and decelerates. linearity controls the sharpness of the curve — lower values produce a sharper ease-out.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
t | number | yes | Normalized progress value in [0, 1] |
linearity | number | no | Controls the sharpness of the curve. Defaults to 0.5 |
Returns
| Type | Description |
|---|---|
number | Eased value in [0, 1] |
Examples
math.easeOut(0) // 0
math.easeOut(0.5) // 0.75
math.easeOut(1) // 1cubicBezier
Signature
math.cubicBezier(t, x1 = 0.42, y1 = 0, x2 = 0.58, y2 = 1)Description
Evaluates a cubic Bézier curve at t. The default control points (0.42, 0, 0.58, 1) produce a standard ease-in-out curve, equivalent to the CSS ease-in-out timing function.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
t | number | yes | Normalized progress value in [0, 1] |
x1 | number | no | X coordinate of the first control point. Defaults to 0.42 |
y1 | number | no | Y coordinate of the first control point. Defaults to 0 |
x2 | number | no | X coordinate of the second control point. Defaults to 0.58 |
y2 | number | no | Y coordinate of the second control point. Defaults to 1 |
Returns
| Type | Description |
|---|---|
number | The Y value of the curve at t |
Examples
math.cubicBezier(0) // 0
math.cubicBezier(0.5) // ~0.5 (symmetric curve)
math.cubicBezier(1) // 1
// CSS ease equivalent
math.cubicBezier(0.5, 0.25, 0.1, 0.25, 1)sum
Signature
math.sum(values)Description
Returns the sum of an array of numbers.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
values | number[] | yes | Array of numbers |
Returns
| Type | Description |
|---|---|
number | The sum of all values. Returns 0 for an empty array |
Examples
math.sum([1, 2, 3, 4]) // 10
math.sum([]) // 0average
Signature
math.average(values)Description
Returns the arithmetic mean of an array of numbers.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
values | number[] | yes | Non-empty array of numbers |
Returns
| Type | Description |
|---|---|
number | The arithmetic mean |
Examples
math.average([1, 2, 3, 4]) // 2.5
math.average([5]) // 5median
Signature
math.median(values)Description
Returns the median of an array of numbers. For even-length arrays, returns the average of the two middle values.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
values | number[] | yes | Non-empty array of numbers |
Returns
| Type | Description |
|---|---|
number | The median value |
Examples
math.median([1, 2, 3, 4, 5]) // 3
math.median([1, 2, 3, 4]) // 2.5
math.median([5, 1, 3]) // 3