math Namespace
The math namespace contains the following API elements to help you include common mathematical tasks in your apps.
Functions
The math namespace provides the following functions.
math.floor
This API converts a float value to an integer. The converted integer value is always the integer part of the specified float number (number before the decimal).
Syntax
Return Values
Return Value | Description |
---|---|
integer [Number] | The return value is an integer |
Example
Platform Availability
Available on all platforms.
math.max
This API returns the maximum value among the arguments.
Syntax
Return Values
Return Value | Description |
---|---|
Maximum Value [Number] | The return value is the maximum value among all the arguments |
Example
Platform Availability
Available on all platforms.
math.min
This API returns the minimum value among the arguments.
Syntax
Return Values
Return Value | Description |
---|---|
Minimum Value [Number] | The return value is the minimum value among all the arguments |
Example
Platform Availability
Available on all platforms.
math.pi
This API returns the value of pi.
Note: math.pi is not a function, but a property in math namespace.
Syntax
Input Parameters
None.
Return Values
Return Value | Description |
---|---|
value of pi [Number] | Value of pi is returned |
Example
Platform Availability
Available on all platforms.
math.pow
This API raises the first parameter to the power of the second parameter and returns the result.
Syntax
Return Values
Return Value | Description |
---|---|
xy | Raises the first parameter to the power of the second parameter |
Implementation Details
It is advisable to use the expression x^y as it is much faster when compared to this API.
Example
Platform Availability
Available on all platforms.
math.random
This API generates pseudo-random numbers which are uniformly distributed. This API generates a real number between 0 and 1.
Syntax
Math.random()
Return Values
Return Value | Description |
---|---|
pseudo-random number [Number] | A pseudo-random number between the value 0 and 1 is generated |
Example
Platform Availability
Available on all platforms.
math.sqrt
This API returns the square root of the given number.
Syntax
Math.sqrt()
Return Values
Return Value | Description |
---|---|
square root [Number] | The square root of the number is returned |
nan (not a number) | This value is returned when the input parameter is a negative number |
Example
Platform Availability
Available on all platforms.