spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column63


WMLScript Standard Libraries

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

The Float Library

This library includes a set of typical arithmetic functions that are normally part of the JavaScript language. The support of this library is optional. It is implemented only by devices that can support floating-point numbers. All functions should return invalid if floating-point numbers are not supported.

int()

This function returns the integer part of the given value.

Syntaxint(value)
Parametersvalue = Number
ReturnsInteger or invalid
Examples:var a = Float.int(9.53); // a = 9
var b = Float.int("foobar"); // b = invalid

floor()

This function returns the greatest integer value that is not greater than the given value.

Syntaxfloor(value)
Parametersvalue = Number
ReturnsInteger or invalid
Examples:var a = Float.floor(9.53); // a = 9
var b = Float.floor(-9.53); // b = -10
var c = Float.floor("foobar"); // c = invalid

ceil()

This function returns the smallest integer value that is not smaller than the given value.

Syntaxceil(value)
Parametersvalue = Number
ReturnsInteger or invalid
Examples:var a = Float.floor(9.13); // a = 10
var b = Float.floor(-9.53); // b = -9
var c = Float.floor("foobar"); // c = invalid

pow()

This function returns the result of raising the first parameter to the power of the second parameter. If the first parameter is negative, the second parameter must be an integer. Otherwise, invalid is returned. The result is implementation-dependent.

Syntaxpow(value1, value2)
Parametersvalue1 = Number
value2 = Number
ReturnsFloating-point number or invalid ((if value1 == 0 and value2 < 0) or (if value1 < 0 and value2 is not an integer))
Examples:var a = Float.pow(4, 2); // a = 16
var b = Float.pow(-2, 3); // b = 8
var c = Float.pow(-2, -3); // c = invalid
var d = Float.pow(-2, "foobar"); // d = invalid

round()

This function returns the closest integer value. If two integer numbers are equally close, the larger one is returned.

Syntaxround(value)
Parametersvalue = Number
ReturnsInteger or invalid
Examples:var a = Float.round(9.5); // a = 10
var b = Float.floor(-9.53); // b = -9

sqrt()

This function returns the square root of the given value. The result is implementation-dependent. invalid is returned if the parameter is negative or not a number.

Syntaxsqrt(value)
Parametersvalue = Floating-point number
ReturnsFloating-point number or invalid
Examples:var a = Float.sqrt(4); // a = 2
var b = Float.sqrt(6.25); // b = 2.5
var c = Float.sqrt("-8"); // c = invalid

maxFloat()

This function returns the maximum floating-point number supported by single-precision floating-point format.

SyntaxmaxFloat()
Parametersnone
ReturnsFloating-point number(3.40282347E+38)
Examples:var a = Float.maxFloat(); // a = 3.40282347E+38

minFloat()

This function returns the minimum floating-point number supported by single-precision floating-point format.

SyntaxminFloat()
Parametersnone
ReturnsFloating-point number (1.17549435E-38)
Examples:var a = Float.minFloat(); // a = 1.17549435E-38

Next: How to use String library - Part I

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Created: June 5, 2000
Revised: June 5, 2000

URL: http://www.webreference.com/js/column63/4.html