Math Functions

  • Updated

This page outlines arithmetic/math functions in NetScript.

Basic Operations

This section lists the basic math operations you can perform using NetScript.

number + number

This function returns the sum of the inputs.

Function: number + number

Data Type: number

Example:

5 + 7
Result:
12

 

number - number

This function returns the difference of the inputs.

Function: number - number

Data Type: number

Example:

13-10
Result:
3

 

number * number

This function returns the product of the inputs.

Function: number * number

Data Type: number

Example:

7 * 8
Result:
56

 

number / number

This function returns the division of the inputs.

Function: number / number

Data Type: number

Example:

84 / 4
Result:
21

 

number ^ number

This function returns number1  raised to the power of number2 .

Function: number ^ number

Data Type: number

Example:

2 ^ 9
Result:
512

 

Advanced Operations

This table lists the advanced operations you can invoke using NetScript:

floor(number)

This function rounds the number down to the nearest integer.

Function: floor(number)

Data Type: number

Example:

floor(17.36)
Result:
17

 

round(number[, N])

This function rounds the number to the given precision (N), which is 0 by default. Precision value can be positive or negative and indicates the number of decimal places displayed in the rounded number.

Function: round(number[, <N>])

Data Type: number

Example:

round(23.45)
round(23.45, 0)
round(23.45, 1)
round(23.45, -1)
Result:
23
23
23.5
20

 

truncate(number[, N])

This function rounds the number down to the given precision (N), which is 0 by default.

Function: truncate(number[, <N>])

Data Type: number

Example:

truncate(23.45)
truncate(23.45, 0)
truncate(23.45, 1)
truncate(23.45, -1)
Result:
23
23
23.4
20

 

sqrt(number)

This function returns the square root (full-precision decimal) of the input.

Function: sqrt(number)

Data Type: number

Example:

sqrt(64)
Result:
8

 

least(number(, number)*)

This function returns whichever number has the smallest value.

Function: least(number(, number)*)

Data Type: number

Example:

least(7(, 23)*)
Result:
7

 

greatest(number(, number)*)

This function returns whichever number  has the largest value.

Function: greatest(number(, number)*)

Data Type: number

Example:

greatest(7(, 23)*)
Result:
23