Functions

Math Functions

Mathematical functions and constants accessed through the math namespace.

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

ConstantValueDescription
math.E2.718Euler's number, base of natural logarithms
math.PI3.142Ratio of a circle's circumference to its diameter
math.SQRT21.414Square root of 2
math.SQRT1_20.707Square root of 1/2
math.LN20.693Natural logarithm of 2
math.LN102.303Natural logarithm of 10
math.LOG2E1.443Base-2 logarithm of E
math.LOG10E0.434Base-10 logarithm of E

Basic

FunctionSignatureDescription
math.absmath.abs(value)Absolute value of a number
math.signmath.sign(value)Sign of a number — returns 1, -1, or 0
math.randommath.random()Random number between 0 and 1

Rounding

FunctionSignatureDescription
math.ceilmath.ceil(value)Smallest integer greater than or equal to value
math.floormath.floor(value)Largest integer less than or equal to value
math.roundmath.round(value)Rounded to the nearest integer
math.truncmath.trunc(value)Integer part — strips the fractional digits

Comparison

FunctionSignatureDescription
math.maxmath.max(a, b, ...)Largest of the given numbers
math.minmath.min(a, b, ...)Smallest of the given numbers

Trigonometric (radians)

FunctionSignatureDescription
math.sinmath.sin(value)Sine
math.cosmath.cos(value)Cosine
math.tanmath.tan(value)Tangent
math.asinmath.asin(value)Arcsine
math.acosmath.acos(value)Arccosine
math.atanmath.atan(value)Arctangent
math.atan2math.atan2(y, x)Arctangent of y/x, preserving quadrant

Hyperbolic

FunctionSignatureDescription
math.sinhmath.sinh(value)Hyperbolic sine
math.coshmath.cosh(value)Hyperbolic cosine
math.tanhmath.tanh(value)Hyperbolic tangent
math.asinhmath.asinh(value)Inverse hyperbolic sine
math.acoshmath.acosh(value)Inverse hyperbolic cosine
math.atanhmath.atanh(value)Inverse hyperbolic tangent

Exponential & Logarithmic

FunctionSignatureDescription
math.expmath.exp(value)e raised to the given power
math.expm1math.expm1(value)e^x - 1 (precise for small x)
math.logmath.log(value)Natural logarithm
math.log1pmath.log1p(value)Natural logarithm of 1 + x (precise for small x)
math.log2math.log2(value)Base-2 logarithm
math.log10math.log10(value)Base-10 logarithm
math.powmath.pow(base, exponent)base raised to exponent

Roots

FunctionSignatureDescription
math.sqrtmath.sqrt(value)Square root
math.cbrtmath.cbrt(value)Cube root
math.hypotmath.hypot(a, b, ...)Square root of the sum of squares