Maths

Common maths functions

Functions

abs(x) → {number}

The abs() function returns the absolute value of a number.

Parameters:
Name Type Description
x number

Required. A number

Returns:
Type:
number

A Number, representing the absolute value of the specified number

Example
// returns 7.25
abs(-7.25)

ceiling(x) → {number}

The ceiling() function rounds a number UPWARDS to the nearest integer, and returns the result.

Parameters:
Name Type Description
x number

Required. The number you want to round

Returns:
Type:
number

A Number, representing the nearest integer when rounding upwards

Example
// returns 2
ceiling(1.4)

floor(x) → {number}

The floor() function rounds a number DOWNWARDS to the nearest integer, and returns the result.

Parameters:
Name Type Description
x number

Required. The number you want to round

Returns:
Type:
number

A Number, representing the nearest integer when rounding downwards

Example
// returns 4
floor(4.7)

ln() → {number}

The ln function returns the natural logarithm of 2, approximately 0.693.

Returns:
Type:
number

A Number, representing the natural logarithm of 2

Example
ln()

log(x) → {number}

The log() function returns the natural logarithm (base E) of a number.

Parameters:
Name Type Description
x number

Required. A number

Returns:
Type:
number

A Number, representing the natural logarithm of a specified number

Example
log(2)

mod(x, y) → {number}

The mod function returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend.

Parameters:
Name Type Description
x number

Required. The dividend

y number

Required. The divisor

Returns:
Type:
number

A Number, the division remainder

Example
// returns 7
mod(15, 8)

pi() → {number}

The PI function returns the ratio of a circle's area to the square of its radius, approximately 3.14

Returns:
Type:
number

A Number, representing PI

Example
// returns PI
pi()

pow(x, y) → {number}

The pow() function returns the value of x to the power of y

Parameters:
Name Type Description
x number

Required. The base

y number

Required. The exponent

Returns:
Type:
number

A Number, representing the value of x to the power of y.

Example
// returns 9
pow(3, 2)

random() → {number}

The random() function returns a random number from 0 (inclusive) up to but not including 1 (exclusive).

Returns:
Type:
number

A Number, representing a number from 0 up to but not including 1

Example
random()

round(x) → {number}

The round() function rounds a number to the nearest integer.

Parameters:
Name Type Description
x number

Required. The number to be rounded

Returns:
Type:
number

A number, representing the nearest integer

Example
// returns 3
round(2.5)

sqrt(x) → {number}

The sqrt() function returns the square root of a number.

Parameters:
Name Type Description
x number

Required. A number

Returns:
Type:
number

A Number. If x is a negative number, NaN is returned

Example
// returns 3
sqrt(9)