Math type
The math type provides trigonometric and other advanced mathematical functions and constants. For commonly used, simple mathematical functions take a look at the number type.
Usage
To use any of the functions described on this page, you must prefix them with the math type name.
Math.sin(90)
Constants
| name | description |
|---|---|
pi | the number pi |
e | the number e (natural logarithmic base) |
Functions
| name | description |
|---|---|
| abs(number) | gets the absolute value of a number |
| sqrt(number) | gets the square root of a number |
| random(max) | gets a random number |
| max(number1, number2) | gets the greater of two numbers |
| min(number1, number2) | gets the lower of two numbers |
| log(number) | gets the natural logarithm (base e) of a number |
| log2(number) | gets the base 2 logarithm of a number |
| log10(number) | gets the base 10 logarithm of a number |
Trigonometric Functions (in degrees)
These functions assume that angles are measured in degrees, see the next section for corresponding functions that take radians.
| name | description |
|---|---|
| sin(angle) | gets the sine of the specified angle |
| cos(angle) | gets the cosine of the specified angle |
| tan(angle) | gets the tangent of a specified angle |
| asin(number) | gets the angle whose sine is the specified number |
| acos(number) | gets the angle whose cosine is the specified number |
| atan(number) | gets the angle whose tangent is the specified number |
Trigonometric Functions (in radians)
These functions assume that angles are measured in radians, otherwise they behave exactly like their degree counterparts.
| name | description |
|---|---|
| sinr(angle) | gets the sine of the specified angle |
| cosr(angle) | gets the cosine of the specified angle |
| tanr(angle) | gets the tangent of a specified angle |
| asinr(number) | gets the angle whose sine is the specified number |
| acosr(number) | gets the angle whose cosine is the specified number |
| atanr(number) | gets the angle whose tangent is the specified number |
abs(number)
Returns the absolute value of a number.
| example | result |
|---|---|
Math.abs(-13.37) | 13.37 |
Math.abs(5) | 5 |
sqrt(number)
Returns the square root of a number.
| example | result |
|---|---|
Math.sqrt(4) | 2 |
log(number)
Returns the natural logarithm (base e) of a number.
| example | result |
|---|---|
Math.log(2) | 0.693147180559945 |
log2(number)
Returns the base 2 logarithm of a number.
| example | result |
|---|---|
Math.log2(2) | 1 |
log10(number)
Returns the base 10 logarithm of a number.
| example | result |
|---|---|
Math.log10(2) | 0.301029995663981 |
max(number1, number2)
Returns the greater of two numbers.
| example | result |
|---|---|
Math.max(3, 5) | 5 |
Math.max(-7, -2) | -2 |
min(number1, number2)
Returns the lesser of two numbers.
| example | result |
|---|---|
Math.min(3, 5) | 3 |
Math.min(-7, -2) | -7 |