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
Math.sqrt(9) Math.pow(2, 3) Math.PI
API list
| API | Description |
|---|---|
| Math constant | Provides mathematical constants such as E, PI, TAU, etc. |
| Math.abs | Returns the absolute value of value. |
| Math.pow | Returns value raised to the power. |
| Math.sqrt | Returns the square root of value. |
| Math.cbrt | Returns the cube root of value. |
| Math.min | Returns the minimum value among all parameters. |
| Math.max | Returns the maximum value among all parameters. |
| Math.clamp | Return min when value is less than min, return max when greater than max, otherwise return value. |
| Math.sign | Returns -1 for negative numbers, 0 for zero, and 1 for positive numbers. |
| Math.hypot | Returns the length of the hypotenuse of sqrt(x x + y y). |
| Math.round | Returns the rounded number. |
| Math.ceil | Returns the smallest integer greater than or equal to value. |
| Math.floor | Returns the largest integer less than or equal to value. |
| Math.trunc | Returns the number after removing the decimal part. |
| Math.exp | Returns e raised to the power of value. |
| Math.exp2 | Returns 2 raised to the power of value. |
| Math.expm1 | Return exp(value) - 1. |
| Math.ln | Returns the natural logarithm of value. |
| Math.log | Returns the base logarithm of value. |
| Math.log10 | Returns the base 10 logarithm of value. |
| Math.log2 | Returns the base 2 logarithm of value. |
| Math.log1p | Return ln(1 + value). |
| Math.sin | Returns the sine of value. |
| Math.cos | Returns the cosine of value. |
| Math.tan | Returns the tangent of value. |
| Math.asin | Returns the arcsine of value in radians. |
| Math.acos | Returns the arc cosine of value in radians. |
| Math.atan | Returns the arctangent of value in radians. |
| Math.atan2 | Returns the bearing angle in radians based on y and x. |
| Math.rad | Returns the corresponding radian value. |
| Math.deg | Returns the corresponding angle value. |
| Math.sinh | Returns the hyperbolic sine of value. |
| Math.cosh | Returns the hyperbolic cosine of value. |
| Math.tanh | Returns the hyperbolic tangent of value. |
| Math.asinh | Returns the inverse hyperbolic sine of value. |
| Math.acosh | Returns the inverse hyperbolic cosine of value. |
| Math.atanh | Returns the inverse hyperbolic tangent of value. |
| Math.random | Returns a random floating point number 0 <= n < 1. |
Constant
| Constant | Description |
|---|---|
| Math.E | Natural constant e. |
| Math.LN2 | The natural logarithm of 2. |
| Math.LN10 | The natural logarithm of 10. |
| Math.LOG2E | Base 2 logarithm of e. |
| Math.LOG10E | Base 10 logarithm of e. |
| Math.PI | Pi. |
| Math.SQRT1_2 | The reciprocal of the square root of 2. |
| Math.SQRT2 | The square root of 2. |
| Math.TAU | 2 times pi. |
Examples
// Output: 8 print Math.pow(2, 3) // Output: 3 print Math.sqrt(9) // Output: 3.141592653589793 print Math.PI
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.