Math Math Library

Math Math Library

Math Math Library

Function

Math is a global stateless static mathematical object that provides mathematical constants, basic mathematics, rounding, exponents, logarithms, trigonometric functions, hyperbolic functions and random number capabilities.

Syntax

API list

APIDescription
Math constant Provides mathematical constants such as E, PI, TAU, etc.
Math.absReturns the absolute value of value.
Math.powReturns value raised to the power.
Math.sqrtReturns the square root of value.
Math.cbrtReturns the cube root of value.
Math.minReturns the minimum value among all parameters.
Math.maxReturns the maximum value among all parameters.
Math.clampReturn min when value is less than min, return max when greater than max, otherwise return value.
Math.signReturns -1 for negative numbers, 0 for zero, and 1 for positive numbers.
Math.hypotReturns the length of the hypotenuse of sqrt(x x + y y).
Math.roundReturns the rounded number.
Math.ceilReturns the smallest integer greater than or equal to value.
Math.floorReturns the largest integer less than or equal to value.
Math.truncReturns the number after removing the decimal part.
Math.expReturns e raised to the power of value.
Math.exp2Returns 2 raised to the power of value.
Math.expm1Return exp(value) - 1.
Math.lnReturns the natural logarithm of value.
Math.logReturns the base logarithm of value.
Math.log10Returns the base 10 logarithm of value.
Math.log2Returns the base 2 logarithm of value.
Math.log1pReturn ln(1 + value).
Math.sinReturns the sine of value.
Math.cosReturns the cosine of value.
Math.tanReturns the tangent of value.
Math.asinReturns the arcsine of value in radians.
Math.acosReturns the arc cosine of value in radians.
Math.atanReturns the arctangent of value in radians.
Math.atan2Returns the bearing angle in radians based on y and x.
Math.radReturns the corresponding radian value.
Math.degReturns the corresponding angle value.
Math.sinhReturns the hyperbolic sine of value.
Math.coshReturns the hyperbolic cosine of value.
Math.tanhReturns the hyperbolic tangent of value.
Math.asinhReturns the inverse hyperbolic sine of value.
Math.acoshReturns the inverse hyperbolic cosine of value.
Math.atanhReturns the inverse hyperbolic tangent of value.
Math.randomReturns a random floating point number 0 <= n < 1.

Constant

ConstantDescription
Math.ENatural constant e.
Math.LN2The natural logarithm of 2.
Math.LN10The natural logarithm of 10.
Math.LOG2EBase 2 logarithm of e.
Math.LOG10EBase 10 logarithm of e.
Math.PIPi.
Math.SQRT1_2The reciprocal of the square root of 2.
Math.SQRT2The square root of 2.
Math.TAU2 times pi.

Examples

Notes

  • Math is a global static object and creating objects using math() is neither required nor supported anymore.
  • Math.min() and Math.max() require at least 1 numeric argument.
- Numeric results return an Int when possible; results that are not integers, non-finite values, or outside the i64 range return a Float.