The Float library contains a set of typical floating-point functions that are frequently used by applications. The implementation of these library functions is optional and implemented only by devices that can support floating-point operations. If floating-point operations are not supported, all functions in this library must return invalid.
Included in this section are the following function calls:
float.ceil(value)
Returns the smallest integer value that is not less than the given value. If the value is already an integer, the result is the value itself.
value = Number
Integer or invalid
var a = 3.14;
var b = Float.ceil(a); // b = 4
var c = Float.ceil(-2.8); // c = -2
float.floor(value)
Returns the greatest integer value that is not greater than the given value. If the value is already an integer, the result is the value itself.
value = Number
Integer or invalid
var a = 3.14;
var b = Float.floor(a); // b = 3
var c = Float.floor(-2.8); // c = -3
float.int(value)
Returns the integer part of the given value. If the value is already an integer, the result is the value itself.
value = Number
Integer or invalid
var a = 3.14;
var b = Float.int(a); // b = 3
var c = Float.int(-2.8); // c = -2
float.maxFloat()
Returns the maximum floating-point value supported by single-precision floating-point format.
Floating-point 3.40282347E+38
var a = Float.maxFloat();
float.minFloat()
Returns the smallest nonzero floating-point value supported by single-precision floating-point format.
Floating-point 1.17549435E-38
var a = Float.minFloat();
float.pow(value1, value2)
Returns an implementation-dependent approximation to the result of raising value1 to the power of value2. If value1 is a negative number, then value2 must be an integer.
value1 = Number
value2 = Number
Floating-point or invalid.
If value1 == 0 and value2 < 0, then invalid is returned.
If value1 < 0 and value2 is not an integer, then invalid is returned.
var a = 3;
var b = Float.pow(a, 2); // b = 9
var c = 2.78
var d = float.pow(c, 3) // d = 2.783
float.round(value)
Returns the number value that is closest to the given value and is equal to a mathematical integer. If two integer number values are equally close to the value, the result is the largest number value. If the value is already an integer, the result is the value itself.
value = Number
Integer or invalid
var a = Float.round(3.5); // a = 4
var b = Float.round(-3.5); // b = -3
var c = Float.round(0.5); // c = 1
var d = Float.round(-0.5); // d = 0
float.sqrt(value)
Returns an implementation-dependent approximation to the square root of the given value.
value = Floating-point
Floating-point or invalid.
If value is a negative number then invalid is returned.
var a = 4;
var b = Float.sqrt(a); // b = 2.0
var c = Float.sqrt(5); // c = 2.2360679775