Skip to main content

Mathematical Functions

abs

abs(number)
Examples
abs(-1) // => 1

Description

Returns the absolute value of a number.

Return type

Number


sqrt

sqrt(number)
Examples
sqrt(9) // => 3
sqrt(10) // => 3.1622776601683795

Description

Returns the square root of a number.

Return type

Number


ceil

ceil(number)
Examples
ceil(1.1) // => 2
ceil(1.9) // => 2

Description

Returns the smallest integer greater than or equal to a number.

Return type

Number

floor

floor(number)
Examples
floor(1.1) // => 1
floor(1.9) // => 1

Description

Returns the largest integer less than or equal to a number.

Return type

Number

round

round(number)
round(number, scale)
Examples
round(1.1) // => 1
round(1.1, 0) // => 1
round(1.9, 0) // => 2
round(1.12345, 2) // => 1.12
round(-1.5) // => -2

Description

Returns the rounded value of a number to a specified number of decimal places (scale). Round away from zero if the fractional part of the number is greater than 0.5; otherwise, round towards zero.

Return type

Number

trunc

trunc(number)
trunc(number, scale)
Examples
trunc(1.1) // => 1
trunc(1.1, 0) // => 1
trunc(1.9, 0) // => 1
trunc(1.12345, 2) // => 1.12

Description

Returns the truncated value of a number to a specified number of decimal places (scale).

Return type

Number

exp

exp(number)
Examples
exp(1) // => 2.718281828459045

Description

Returns the value of the constant ee raised to the power of a number.

Return type

Number

ln

ln(number)
Examples
ln(1) // => 0

Description

Returns the natural logarithm (loge\log_e) of a number.

Return type

Number

log10

log10(number)
Examples
log10(100) // => 2

Description

Returns the base 10 logarithm (log10\log_{10}) of a number.

Return type

Number

log2

log2(number)
Examples
log2(8) // => 3

Description

Returns the base 2 logarithm (log2\log_{2}) of a number.

Return type

Number

pow

pow(base, exponent)
Examples
pow(2, 3) // => 8

Description

Returns the value of a base raised to the power of an exponent.

Return type

Number

mod

mod(dividend, divisor)
Examples
mod(5, 2) // => 1

Description

Returns the remainder of a division operation.

Return type

Number

div

div(dividend, divisor)
Examples
div(5, 2) // => 2

Description

Returns the integer quotient of a division operation.

Return type

Number

sign

sign(number)
Examples
sign(5) // => 1
sign(-5) // => -1
sign(0) // => 0

Description

Returns the sign of a number: 1 if the number is positive, -1 if the number is negative, and 0 if the number is zero.

Return type

Number

radians

radians(degrees)
Examples
radians(180) // => 3.141592653589793

Description

Converts degrees to radians.

Return type

Number

degrees

degrees(radians)
Examples
degrees(pi()) // => 180

Description

Converts radians to degrees.

Return type

Number

pi

pi()
Examples
pi() // => 3.141592653589793

Description

Returns the value of the constant π\pi.

Return type

Number

acos

acos(number)
Examples
acos(cos(pi())) // => 3.141592653589793

Description

Returns the arccosine of a number.

Return type

Number

asin

asin(number)
Examples
asin(sin(pi() / 2)) // => 1.5707963267948966

Description

Returns the arcsine of a number.

Return type

Number

atan

atan(number)
Examples
atan(tan(pi() / 4)) // => 0.7853981633974483

Description

Returns the arctangent of a number.

Return type

Number

atan2

atan2(y, x)
Examples
atan2(2, pi()) // => 0.6366197723675814

**Description**

Returns the 2-argument arctangent.

**Return type**

Number

### cos

```jsx
cos(number)
Examples
cos(pi()) // => -1

Description

Returns the cosine of a number.

Return type

Number

sin

sin(number)
Examples
sin(pi() / 2) // => 1

Description

Returns the sine of a number.

Return type

Number

tan

tan(number)
Examples
tan(pi() / 4) // => 1

Description

Returns the tangent of a number.

Return type

Number

cot

cot(number)
Examples
cot(pi() / 4) // => 1

Description

Returns the cotangent of a number.

Return type

Number


Let us know what you think about this document :)