
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
82
|
Chapter 4: Primitive Datatypes
Number.MAX_VALUE comes in handy when we are checking to see if a calculation results
in a representable number:
z = x*y;
if (z <= Number.MAX_VALUE && z >= –Number.MAX_VALUE) {
// Number is legal
}
Note that Number.MIN_VALUE is the smallest positive value allowed, not the most nega-
tive value. The “largest” negative legal value is
–Number.MAX_VALUE.
Infinity and negative infinity: Infinity and -Infinity
If a calculation results in a value larger than Number.MAX_VALUE, ActionScript uses the
keyword
Infinity to represent the result of the calculation (this is known as an over-
flow condition). Similarly, if a calculation results in a value more negative than the
“largest” allowable negative value, ActionScript uses
–Infinity to represent the result
(this is known as a negative overflow condition).
Infinity and –Infinity can also be
used directly as literal numeric expressions.
Irrational numbers
In addition to the special numeric values—NaN, Infinity, –Infinity, Number.MAX_VALUE,
and
Number.MIN_VALUE—ActionScript provides convenient access to mathematical con-
stants via the Math object. For example:
Math.E // The value of e, the base of the natural logarithm
Math.LN10 // Natural logarithm of 10
Math.LN2 // Natural logarithm of 2
Math.LOG10E // Base-10 logarithm of ...