Math functions
#
absThe 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:
Param | Data type | Description |
---|---|---|
numberValue | Number | The number whose absolute value will be returned. |
Returns: Number
Example:
value = new NameSpace("math").abs(100.23);log value;
#
ceilThe 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:
Param | Data type | Description |
---|---|---|
numberValue | Number | The nearest largest integer to this value will be returned. |
Returns: Number
Example:
value = new NameSpace("math").ceil(100.23);log value; // 101
#
floorThe 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:
Param | Data type | Description |
---|---|---|
numberValue | Number | The nearest smallest integer to this value will be returned. |
Returns: Number
Example:
value = new NameSpace("math").floor(100.23);log value; // 100
#
powThe 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:
Param | Data type | Description |
---|---|---|
baseNumber | Number | Value to be raised to powerNumber. |
powerNumber | Number | The power to which the baseNumber will be raised. |
Returns: Number
Example:
value = new NameSpace("math").pow(100, 2);log value; // 10000
#
cbrtThe cbrt() function takes a number as an argument, and returns the cube root of that number.
Syntax:
new NameSpace("math").cbrt(
Number
numberValue)
Parameters:
Param | Data type | Description |
---|---|---|
numberValue | Number | The number whose cube root will be returned. |
Returns: Number
Example:
value = new NameSpace("math").cbrt(100);log value; // 4.641588833612779
#
sqrtThe sqrt() function takes a number as an argument, and returns the square root of that number.
Syntax:
new NameSpace("math").sqrt(
Number
numberValue)
Parameters:
Param | Data type | Description |
---|---|---|
numberValue | Number | The number whose square root will be returned. |
Returns: Number
Example:
value = new NameSpace("math").sqrt(100);log value; // 10
#
randomThe random() function generates a random number from the specified range.
Syntax:
new NameSpace("math").random(
Number
maxLimit)
Parameters:
Param | Data type | Description |
---|---|---|
maxLimit | Number | The max limit of the which the random number needs to generated. |
Returns: Number
Example:
value = new NameSpace("math").random(100);log value;
#
setPrecisionThe 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:
Param | Data type | Description |
---|---|---|
numberValue | Number | The number value. |
precisionValue | Number | The precision value. |
Returns: Number
Example:
numberValue = 100.234;
value = new NameSpace("math").setPrecision(numberValue, 2);log value; // 100.23
#
setPrecisionWithCeilingThe 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:
Param | Data type | Description |
---|---|---|
numberValue | Number | The number value. |
precisionValue | Number | The precision value. |
Returns: Number
Example:
numberValue = 100.234;
value = new NameSpace("math").setPrecision(numberValue, 2);log value; // 100.24
#
expThe 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:
Param | Data type | Description |
---|---|---|
numberValue | Number | The number value. |
Returns: Number
Example:
value = new NameSpace("math").exp(4.0);log value; //54.598150033144236
#
lnThe 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:
Param | Data type | Description |
---|---|---|
numberValue | Number | The number value. |
Returns: Number
Example:
value = new NameSpace("math").ln(9.0);log value; //2.1972245773362196
#
getLogThe 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:
Param | Data type | Description |
---|---|---|
numberValue | Number | The number value. |
Returns: Number
Example:
value = new NameSpace("math").getLog(9.0);log value; // 0.9542425094393249