# 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 ```bt Math.sqrt(9) Math.pow(2, 3) Math.PI ``` ## API list | API | Description | | ------ | ------ | | [Math constant ](/en/docs/math/constants) | Provides mathematical constants such as E, PI, TAU, etc. | | [Math.abs](/en/docs/math/abs) | Returns the absolute value of value. | | [Math.pow](/en/docs/math/pow) | Returns value raised to the power. | | [Math.sqrt](/en/docs/math/sqrt) | Returns the square root of value. | | [Math.cbrt](/en/docs/math/cbrt) | Returns the cube root of value. | | [Math.min](/en/docs/math/min) | Returns the minimum value among all parameters. | | [Math.max](/en/docs/math/max) | Returns the maximum value among all parameters. | | [Math.clamp](/en/docs/math/clamp) | Return min when value is less than min, return max when greater than max, otherwise return value. | | [Math.sign](/en/docs/math/sign) | Returns -1 for negative numbers, 0 for zero, and 1 for positive numbers. | | [Math.hypot](/en/docs/math/hypot) | Returns the length of the hypotenuse of sqrt(x * x + y * y). | | [Math.round](/en/docs/math/round) | Returns the rounded number. | | [Math.ceil](/en/docs/math/ceil) | Returns the smallest integer greater than or equal to value. | | [Math.floor](/en/docs/math/floor) | Returns the largest integer less than or equal to value. | | [Math.trunc](/en/docs/math/trunc) | Returns the number after removing the decimal part. | | [Math.exp](/en/docs/math/exp) | Returns e raised to the power of value. | | [Math.exp2](/en/docs/math/exp2) | Returns 2 raised to the power of value. | | [Math.expm1](/en/docs/math/expm1) | Return exp(value) - 1. | | [Math.ln](/en/docs/math/ln) | Returns the natural logarithm of value. | | [Math.log](/en/docs/math/log) | Returns the base logarithm of value. | | [Math.log10](/en/docs/math/log10) | Returns the base 10 logarithm of value. | | [Math.log2](/en/docs/math/log2) | Returns the base 2 logarithm of value. | | [Math.log1p](/en/docs/math/log1p) | Return ln(1 + value). | | [Math.sin](/en/docs/math/sin) | Returns the sine of value. | | [Math.cos](/en/docs/math/cos) | Returns the cosine of value. | | [Math.tan](/en/docs/math/tan) | Returns the tangent of value. | | [Math.asin](/en/docs/math/asin) | Returns the arcsine of value in radians. | | [Math.acos](/en/docs/math/acos) | Returns the arc cosine of value in radians. | | [Math.atan](/en/docs/math/atan) | Returns the arctangent of value in radians. | | [Math.atan2](/en/docs/math/atan2) | Returns the bearing angle in radians based on y and x. | | [Math.rad](/en/docs/math/rad) | Returns the corresponding radian value. | | [Math.deg](/en/docs/math/deg) | Returns the corresponding angle value. | | [Math.sinh](/en/docs/math/sinh) | Returns the hyperbolic sine of value. | | [Math.cosh](/en/docs/math/cosh) | Returns the hyperbolic cosine of value. | | [Math.tanh](/en/docs/math/tanh) | Returns the hyperbolic tangent of value. | | [Math.asinh](/en/docs/math/asinh) | Returns the inverse hyperbolic sine of value. | | [Math.acosh](/en/docs/math/acosh) | Returns the inverse hyperbolic cosine of value. | | [Math.atanh](/en/docs/math/atanh) | Returns the inverse hyperbolic tangent of value. | | [Math.random](/en/docs/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 ```bt // 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. - Numeric results return an Int when possible; results that are not integers, non-finite values, or outside the i64 range return a Float.