]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Expressions/11.5.2.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
24 ECMA Section: 11.5.2 Applying the / operator
27 The / operator performs division, producing the quotient of its operands.
28 The left operand is the dividend and the right operand is the divisor.
29 ECMAScript does not perform integer division. The operands and result of all
30 division operations are double-precision floating-point numbers.
31 The result of division is determined by the specification of IEEE 754 arithmetic:
33 If either operand is NaN, the result is NaN.
34 The sign of the result is positive if both operands have the same sign, negative if the operands have different
36 Division of an infinity by an infinity results in NaN.
37 Division of an infinity by a zero results in an infinity. The sign is determined by the rule already stated above.
38 Division of an infinity by a non-zero finite value results in a signed infinity. The sign is determined by the rule
40 Division of a finite value by an infinity results in zero. The sign is determined by the rule already stated above.
41 Division of a zero by a zero results in NaN; division of zero by any other finite value results in zero, with the sign
42 determined by the rule already stated above.
43 Division of a non-zero finite value by a zero results in a signed infinity. The sign is determined by the rule
45 In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the quotient is computed and
46 rounded to the nearest representable value using IEEE 754 round-to-nearest mode. If the magnitude is too
47 large to represent, we say the operation overflows; the result is then an infinity of appropriate sign. If the
48 magnitude is too small to represent, we say the operation underflows and the result is a zero of the appropriate
49 sign. The ECMAScript language requires support of gradual underflow as defined by IEEE 754.
51 Author: christine@netscape.com
52 Date: 12 november 1997
54 var SECTION
= "11.5.2";
55 var VERSION
= "ECMA_1";
57 var testcases
= getTestCases();
58 var BUGNUMBER
="111202";
60 writeHeaderToLog( SECTION
+ " Applying the / operator");
64 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
65 testcases
[tc
].passed
= writeTestCaseResult(
68 testcases
[tc
].description
+" = "+
69 testcases
[tc
].actual
);
71 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
76 function getTestCases() {
77 var array
= new Array();
80 // if either operand is NaN, the result is NaN.
82 array
[item
++] = new TestCase( SECTION
, "Number.NaN / Number.NaN", Number
.NaN
, Number
.NaN
/ Number
.NaN
);
83 array
[item
++] = new TestCase( SECTION
, "Number.NaN / 1", Number
.NaN
, Number
.NaN
/ 1 );
84 array
[item
++] = new TestCase( SECTION
, "1 / Number.NaN", Number
.NaN
, 1 / Number
.NaN
);
86 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY / Number.NaN", Number
.NaN
, Number
.POSITIVE_INFINITY
/ Number
.NaN
);
87 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY / Number.NaN", Number
.NaN
, Number
.NEGATIVE_INFINITY
/ Number
.NaN
);
89 // Division of an infinity by an infinity results in NaN.
91 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY / Number.NEGATIVE_INFINITY", Number
.NaN
, Number
.NEGATIVE_INFINITY
/ Number
.NEGATIVE_INFINITY
);
92 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY / Number.NEGATIVE_INFINITY", Number
.NaN
, Number
.POSITIVE_INFINITY
/ Number
.NEGATIVE_INFINITY
);
93 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY / Number.POSITIVE_INFINITY", Number
.NaN
, Number
.NEGATIVE_INFINITY
/ Number
.POSITIVE_INFINITY
);
94 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY / Number.POSITIVE_INFINITY", Number
.NaN
, Number
.POSITIVE_INFINITY
/ Number
.POSITIVE_INFINITY
);
96 // Division of an infinity by a zero results in an infinity.
98 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY / 0", Number
.POSITIVE_INFINITY
, Number
.POSITIVE_INFINITY
/ 0 );
99 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY / 0", Number
.NEGATIVE_INFINITY
, Number
.NEGATIVE_INFINITY
/ 0 );
100 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY / -0", Number
.NEGATIVE_INFINITY
, Number
.POSITIVE_INFINITY
/ -0 );
101 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY / -0", Number
.POSITIVE_INFINITY
, Number
.NEGATIVE_INFINITY
/ -0 );
103 // Division of an infinity by a non-zero finite value results in a signed infinity.
105 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY / 1 ", Number
.NEGATIVE_INFINITY
, Number
.NEGATIVE_INFINITY
/ 1 );
106 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY / -1 ", Number
.POSITIVE_INFINITY
, Number
.NEGATIVE_INFINITY
/ -1 );
107 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY / 1 ", Number
.POSITIVE_INFINITY
, Number
.POSITIVE_INFINITY
/ 1 );
108 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY / -1 ", Number
.NEGATIVE_INFINITY
, Number
.POSITIVE_INFINITY
/ -1 );
110 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY / Number.MAX_VALUE ", Number
.NEGATIVE_INFINITY
, Number
.NEGATIVE_INFINITY
/ Number
.MAX_VALUE
);
111 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY / -Number.MAX_VALUE ", Number
.POSITIVE_INFINITY
, Number
.NEGATIVE_INFINITY
/ -Number
.MAX_VALUE
);
112 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY / Number.MAX_VALUE ", Number
.POSITIVE_INFINITY
, Number
.POSITIVE_INFINITY
/ Number
.MAX_VALUE
);
113 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY / -Number.MAX_VALUE ", Number
.NEGATIVE_INFINITY
, Number
.POSITIVE_INFINITY
/ -Number
.MAX_VALUE
);
115 // Division of a finite value by an infinity results in zero.
117 array
[item
++] = new TestCase( SECTION
, "1 / Number.NEGATIVE_INFINITY", -0, 1 / Number
.NEGATIVE_INFINITY
);
118 array
[item
++] = new TestCase( SECTION
, "1 / Number.POSITIVE_INFINITY", 0, 1 / Number
.POSITIVE_INFINITY
);
119 array
[item
++] = new TestCase( SECTION
, "-1 / Number.POSITIVE_INFINITY", -0, -1 / Number
.POSITIVE_INFINITY
);
120 array
[item
++] = new TestCase( SECTION
, "-1 / Number.NEGATIVE_INFINITY", 0, -1 / Number
.NEGATIVE_INFINITY
);
122 array
[item
++] = new TestCase( SECTION
, "Number.MAX_VALUE / Number.NEGATIVE_INFINITY", -0, Number
.MAX_VALUE
/ Number
.NEGATIVE_INFINITY
);
123 array
[item
++] = new TestCase( SECTION
, "Number.MAX_VALUE / Number.POSITIVE_INFINITY", 0, Number
.MAX_VALUE
/ Number
.POSITIVE_INFINITY
);
124 array
[item
++] = new TestCase( SECTION
, "-Number.MAX_VALUE / Number.POSITIVE_INFINITY", -0, -Number
.MAX_VALUE
/ Number
.POSITIVE_INFINITY
);
125 array
[item
++] = new TestCase( SECTION
, "-Number.MAX_VALUE / Number.NEGATIVE_INFINITY", 0, -Number
.MAX_VALUE
/ Number
.NEGATIVE_INFINITY
);
127 // Division of a zero by a zero results in NaN
129 array
[item
++] = new TestCase( SECTION
, "0 / -0", Number
.NaN
, 0 / -0 );
130 array
[item
++] = new TestCase( SECTION
, "-0 / 0", Number
.NaN
, -0 / 0 );
131 array
[item
++] = new TestCase( SECTION
, "-0 / -0", Number
.NaN
, -0 / -0 );
132 array
[item
++] = new TestCase( SECTION
, "0 / 0", Number
.NaN
, 0 / 0 );
134 // division of zero by any other finite value results in zero
136 array
[item
++] = new TestCase( SECTION
, "0 / 1", 0, 0 / 1 );
137 array
[item
++] = new TestCase( SECTION
, "0 / -1", -0, 0 / -1 );
138 array
[item
++] = new TestCase( SECTION
, "-0 / 1", -0, -0 / 1 );
139 array
[item
++] = new TestCase( SECTION
, "-0 / -1", 0, -0 / -1 );
141 // Division of a non-zero finite value by a zero results in a signed infinity.
143 array
[item
++] = new TestCase( SECTION
, "1 / 0", Number
.POSITIVE_INFINITY
, 1/0 );
144 array
[item
++] = new TestCase( SECTION
, "1 / -0", Number
.NEGATIVE_INFINITY
, 1/-0 );
145 array
[item
++] = new TestCase( SECTION
, "-1 / 0", Number
.NEGATIVE_INFINITY
, -1/0 );
146 array
[item
++] = new TestCase( SECTION
, "-1 / -0", Number
.POSITIVE_INFINITY
, -1/-0 );
148 array
[item
++] = new TestCase( SECTION
, "0 / Number.POSITIVE_INFINITY", 0, 0 / Number
.POSITIVE_INFINITY
);
149 array
[item
++] = new TestCase( SECTION
, "0 / Number.NEGATIVE_INFINITY", -0, 0 / Number
.NEGATIVE_INFINITY
);
150 array
[item
++] = new TestCase( SECTION
, "-0 / Number.POSITIVE_INFINITY", -0, -0 / Number
.POSITIVE_INFINITY
);
151 array
[item
++] = new TestCase( SECTION
, "-0 / Number.NEGATIVE_INFINITY", 0, -0 / Number
.NEGATIVE_INFINITY
);