All math functions are accessed through the math namespace and use keyword arguments where applicable.
math.abs(value)
math.max(a, b)
math.sin(value)
Mathematical Constants
| Constant | Value | Description |
|---|
math.E | 2.718 | Euler's number, base of natural logarithms |
math.PI | 3.142 | Ratio of a circle's circumference to its diameter |
math.SQRT2 | 1.414 | Square root of 2 |
math.SQRT1_2 | 0.707 | Square root of 1/2 |
math.LN2 | 0.693 | Natural logarithm of 2 |
math.LN10 | 2.303 | Natural logarithm of 10 |
math.LOG2E | 1.443 | Base-2 logarithm of E |
math.LOG10E | 0.434 | Base-10 logarithm of E |
Basic
| Function | Signature | Description |
|---|
math.abs | math.abs(value) | Absolute value of a number |
math.sign | math.sign(value) | Sign of a number — returns 1, -1, or 0 |
math.random | math.random() | Random number between 0 and 1 |
Rounding
| Function | Signature | Description |
|---|
math.ceil | math.ceil(value) | Smallest integer greater than or equal to value |
math.floor | math.floor(value) | Largest integer less than or equal to value |
math.round | math.round(value) | Rounded to the nearest integer |
math.trunc | math.trunc(value) | Integer part — strips the fractional digits |
Comparison
| Function | Signature | Description |
|---|
math.max | math.max(a, b, ...) | Largest of the given numbers |
math.min | math.min(a, b, ...) | Smallest of the given numbers |
Trigonometric (radians)
| Function | Signature | Description |
|---|
math.sin | math.sin(value) | Sine |
math.cos | math.cos(value) | Cosine |
math.tan | math.tan(value) | Tangent |
math.asin | math.asin(value) | Arcsine |
math.acos | math.acos(value) | Arccosine |
math.atan | math.atan(value) | Arctangent |
math.atan2 | math.atan2(y, x) | Arctangent of y/x, preserving quadrant |
Hyperbolic
| Function | Signature | Description |
|---|
math.sinh | math.sinh(value) | Hyperbolic sine |
math.cosh | math.cosh(value) | Hyperbolic cosine |
math.tanh | math.tanh(value) | Hyperbolic tangent |
math.asinh | math.asinh(value) | Inverse hyperbolic sine |
math.acosh | math.acosh(value) | Inverse hyperbolic cosine |
math.atanh | math.atanh(value) | Inverse hyperbolic tangent |
Exponential & Logarithmic
| Function | Signature | Description |
|---|
math.exp | math.exp(value) | e raised to the given power |
math.expm1 | math.expm1(value) | e^x - 1 (precise for small x) |
math.log | math.log(value) | Natural logarithm |
math.log1p | math.log1p(value) | Natural logarithm of 1 + x (precise for small x) |
math.log2 | math.log2(value) | Base-2 logarithm |
math.log10 | math.log10(value) | Base-10 logarithm |
math.pow | math.pow(base, exponent) | base raised to exponent |
Roots
| Function | Signature | Description |
|---|
math.sqrt | math.sqrt(value) | Square root |
math.cbrt | math.cbrt(value) | Cube root |
math.hypot | math.hypot(a, b, ...) | Square root of the sum of squares |