
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Arithmetic Operators
|
119
The operands can be any valid expression. The * symbol used for multiplication is in
lieu of the × (“times”) symbol used in traditional mathematics. If either operand is
not of the number type, and conversion to a number fails, the operation yields
NaN:
6 * 5 // Returns 30
Division
The division operator divides the first operand (the numerator) by the second oper-
and (the divisor) and returns the result (the quotient). Division takes the general
form:
operand1 / operand2
The operands must be valid numeric expressions. The / symbol used for division is
in lieu of the ÷ symbol used in traditional mathematics. If either operand is not of the
number type, and conversion to a number fails, the operation yields
NaN. If it is neces-
sary to express a fractional result, the quotient is a floating-point number, even if
both operands are integers:
20 / 5 // Returns 4
5 / 4 // Returns 1.25; In other languages, the result may be 1, not 1.25
Note that some other languages, such as Director’s Lingo language, return an inte-
ger unless at least one operand is a float.
If the divisor (denominator) is zero:
• The result is
NaN if the numerator is zero or nonnumeric
• The result is
Infinity if the numerator is a positive number
• The result is
–Infinity if the numerator is a negative number ...