Floating Point Library
The Float library contains a set of math functions.
WMLScript Float Library Functions
The Float library works only on clients that support floating-point numbers. If floating-point numbers are not supported, all functions should return invalid.
Function | Description |
Returns the nearest integer that is not smaller than a specified number | |
Returns the nearest integer that is not larger than a specified number | |
Returns the integer part of a specified number | |
Returns the largest possible floating-point number | |
Returns the smallest possible floating-point number | |
Returns the value of x raised to the power of y | |
Rounds a number to the nearest integer | |
Returns the square root of a number |
1) WMLScript ceil() Function
The ceil() function returns the nearest integer that is not smaller than the x parameter value.Syntax
n = Float.ceil(x) |
Part | Description |
n | The integer returned from the function |
x | A number |
Example
var a = Float.ceil(5.32); var b = Float.ceil(5.55); var c = Float.ceil(-5.32); |
Result
a = 6 b = 6 c = -5 |
2) WMLScript floor() Function
The floor() function returns the nearest integer that is not larger than the x parameter.Syntax
n = Float.floor(x) |
Part | Description |
n | The integer returned from the function |
x | A number |
Example
var a = Float.floor(5.32); var b = Float.floor(-5.32); |
Result
a = 5 b = -6 |
3) WMLScript int() Function
The int() function returns the integer part of the x parameter.Syntax
n = Float.int(x) |
Part | Description |
N | The integer returned from the function |
X | A number |
Example
var a = Float.int(5.32); |
Result
a = 5 |
4) WMLScript maxFloat() Function
The maxFloat() function returns the largest possible floating-point number.Syntax
n = Float.maxFloat() |
Part | Description |
n | The largest possible floating-point number (3.40282347E+38) returned from the function |
Example
var a = Float.maxFloat(); |
Result
a = 3.40282347E+38 |
5) WMLScript minFloat() Function
The minFloat() function returns the smallest possible floating-point number.Syntax
n = Float.minFloat() |
Part | Description |
n | The smallest floating-point number (1.17549435-38) returned from the function |
Example
var a = Float.minFloat(); |
Result
a = 1.17549435-38 |
6) WMLScript pow() Function
The pow() function returns the value of x to the power of y (xy).Syntax
n = Float.pow(x,y) |
Part | Description |
n | The floating-point number returned from the function |
x | A number |
y | A number |
Example
var a = Float.pow(4,2); var b = Float.pow(-2,3); |
Result
a = 16 b = -8 |
7) WMLScript round() Function
The round() function rounds the x parameter to the nearest integer.Syntax
n = Float.round(x) |
Part | Description |
n | The integer returned from the function |
x | A number |
Example
var a = Float.round(3.5); var b = Float.round(3.4); |
Result
a = 4 b = 3 |
8) WMLScript sqrt() Function
The sqrt() function returns the square root of the x parameter.Syntax
n = Float.sqrt(x) |
Part | Description |
n | The floating-point number returned from the function |
x | A number |
Example
var a = Float.sqrt(9); var b = Float.sqrt(6.25); |
Result
a = 3 b = 2.5 |
No comments:
Post a Comment