Skip to main content

Math functions

abs#

The abs() function takes a numberValue as an argument, and returns the absolute value of that number, i.e., the number without a sign.

Syntax:

new NameSpace("math").abs(Number numberValue)

Parameters:

ParamData typeDescription
numberValueNumberThe number whose absolute value will be returned.

Returns: Number

Example:

value = new NameSpace("math").abs(100.23);log value;

ceil#

The ceil() function takes a numberValue as an argument, and returns the nearest largest integer to the given decimal value.

Syntax:

new NameSpace("math").ceil(Number numberValue)

Parameters:

ParamData typeDescription
numberValueNumberThe nearest largest integer to this value will be returned.

Returns: Number

Example:

value = new NameSpace("math").ceil(100.23);log value; // 101

floor#

The floor() function takes a numberValue as an argument, and returns the nearest smallest integer to the given decimal value.

Syntax:

new NameSpace("math").floor(Number numberValue)

Parameters:

ParamData typeDescription
numberValueNumberThe nearest smallest integer to this value will be returned.

Returns: Number

Example:

value = new NameSpace("math").floor(100.23);log value; // 100

pow#

The power() function takes baseNumber and powerNumber as arguments. It returns the baseNumber raised to the power of powerNumber.

Syntax:

new NameSpace("math").pow(Number baseNumber, Number powerNumber)

Parameters:

ParamData typeDescription
baseNumberNumberValue to be raised to powerNumber.
powerNumberNumberThe power to which the baseNumber will be raised.

Returns: Number

Example:

value = new NameSpace("math").pow(100, 2);log value; // 10000

cbrt#

The cbrt() function takes a number as an argument, and returns the cube root of that number.

Syntax:

new NameSpace("math").cbrt(Number numberValue)

Parameters:

ParamData typeDescription
numberValueNumberThe number whose cube root will be returned.

Returns: Number

Example:

value = new NameSpace("math").cbrt(100);log value; // 4.641588833612779

sqrt#

The sqrt() function takes a number as an argument, and returns the square root of that number.

Syntax:

new NameSpace("math").sqrt(Number numberValue)

Parameters:

ParamData typeDescription
numberValueNumberThe number whose square root will be returned.

Returns: Number

Example:

value = new NameSpace("math").sqrt(100);log value; // 10

random#

The random() function generates a random number from the specified range.

Syntax:

new NameSpace("math").random(Number maxLimit)

Parameters:

ParamData typeDescription
maxLimitNumberThe max limit of the which the random number needs to generated.

Returns: Number

Example:

value = new NameSpace("math").random(100);log value;

setPrecision#

The setPrecision() function takes a numberValue and precisionValue as an argument, and returns the specified number of decimals.

Syntax:

new NameSpace("math").setPrecision(Number numberValue, Number precisionValue)

Parameters:

ParamData typeDescription
numberValueNumberThe number value.
precisionValueNumberThe precision value.

Returns: Number

Example:

numberValue = 100.234;
value = new NameSpace("math").setPrecision(numberValue, 2);log value; // 100.23

setPrecisionWithCeiling#

The setPrecisionWithCeiling() function takes a numberValue and precisionValue as an argument, and returns the specified number of decimals which will be the nearest largest integer to the given decimal value, since precision is done along with ceiling. For more understanding, refer setPrecision() and ceiling() functions definition and example.

Syntax:

new NameSpace("math").setPrecision(Number numberValue, Number precisionValue)

Parameters:

ParamData typeDescription
numberValueNumberThe number value.
precisionValueNumberThe precision value.

Returns: Number

Example:

numberValue = 100.234;
value = new NameSpace("math").setPrecision(numberValue, 2);log value; // 100.24

exp#

The exp() function takes number as an argument, which rises to the power e (e is the Euler's number whose value is 2.71828) and it returns e pow numberValue for the argument numberValue.

Syntax:

new NameSpace("math").exp(Number numberValue)

Parameters:

ParamData typeDescription
numberValueNumberThe number value.

Returns: Number

Example:

value = new NameSpace("math").exp(4.0);log value; //54.598150033144236

ln#

The ln() method computes the natural logarithm (base e) of the specified value, which takes numberValue as input and returns the natural logarithmic numberValue. The return based on input is listed below,

1. returns the natural logarithm of argument,2. returns NaN if the argument is NaN or less than zero,3. returns positive infinity if the argument is positive infinity,4. returns negative infinity if the argument is zero.

Syntax:

new NameSpace("math").ln(Number numberValue)

Parameters:

ParamData typeDescription
numberValueNumberThe number value.

Returns: Number

Example:

value = new NameSpace("math").ln(9.0);log value; //2.1972245773362196

getLog#

The log() function takes numberValue as an argument, returns are of four types mentioned below

1. returns the base 10 logarithm of numberValue,2. returns NaN if numberValue is NaN or less than zero,3. returns positive infinity if numberValue is positive infinity,4. returns negative infinity if numberValue is zero.

Syntax:

new NameSpace("math").getLog(Number numberValue)

Parameters:

ParamData typeDescription
numberValueNumberThe number value.

Returns: Number

Example:

value = new NameSpace("math").getLog(9.0);log value; // 0.9542425094393249