WMLScript Reference

[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Chapter 8 - Libraries
Section 26 out of 34 total sections , Section 4 out of 9 sections in this chapter


Float Library

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:

Function call 

ceil 

floor 

int 

maxFloat 

minFloat 

pow 

round 

sqrt 



ceil

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.


Parameters

value = Number


Return Value

Integer or invalid


Examples

var a = 3.14;  
var b = Float.ceil(a);            // b = 4  
var c = Float.ceil(-2.8);         // c = -2  


floor

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.


Parameters

value = Number


Return Value

Integer or invalid


Examples

var a = 3.14;  
var b = Float.floor(a);          // b = 3  
var c = Float.floor(-2.8);       // c = -3  


int

float.int(value)  

Returns the integer part of the given value. If the value is already an integer, the result is the value itself.


Parameters

value = Number


Return Value

Integer or invalid


Examples

var a = 3.14;  
var b = Float.int(a);          // b = 3  
var c = Float.int(-2.8);       // c = -2  


maxFloat

float.maxFloat()  

Returns the maximum floating-point value supported by single-precision floating-point format.


Return Value

Floating-point 3.40282347E+38


Examples

var a = Float.maxFloat();  


minFloat

float.minFloat()  

Returns the smallest nonzero floating-point value supported by single-precision floating-point format.


Return Value

Floating-point 1.17549435E-38


Examples

var a = Float.minFloat();  


pow

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.


Parameters

value1 = Number

value2 = Number


Return Value

Floating-point or invalid.


Exceptions

If value1 == 0 and value2 < 0, then invalid is returned.

If value1 < 0 and value2 is not an integer, then invalid is returned.


Examples

var a = 3;  
var b = Float.pow(a, 2);            // b = 9  
var c = 2.78  
var d = float.pow(c, 3)             // d = 2.783  


round

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.


Parameters

value = Number


Return Value

Integer or invalid


Examples

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  


sqrt

float.sqrt(value)  

Returns an implementation-dependent approximation to the square root of the given value.


Parameters

value = Floating-point


Return Value

Floating-point or invalid.


Exceptions

If value is a negative number then invalid is returned.


Examples

var a = 4;  
var b = Float.sqrt(a);          // b = 2.0  
var c = Float.sqrt(5);          // c = 2.2360679775  

[Cover] [Previous Section] [Next Section] [Index]


Part Number DKWS-41-002, UP.SDK Release 4.1, December 2000

Copyright © 1994-2000 Openwave Systems Inc. All rights reserved.
Please send comments and questions to sdk-doc-comments@openwave.com.