initial import
[vuplus_webkit] / Source / JavaScriptCore / 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/
5  *
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.
10  *
11  * The Original Code is Mozilla Communicator client code, released March
12  * 31, 1998.
13  *
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
17  * Rights Reserved.
18  *
19  * Contributor(s): 
20  * 
21  */
22 /**
23     File Name:          11.5.2.js
24     ECMA Section:       11.5.2 Applying the / operator
25     Description:
26
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:
32
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
35       signs.
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
39       already stated above.
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
44       already stated above.
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.
50
51     Author:             christine@netscape.com
52     Date:               12 november 1997
53 */
54     var SECTION = "11.5.2";
55     var VERSION = "ECMA_1";
56     startTest();
57     var testcases = getTestCases();
58     var BUGNUMBER="111202";
59
60     writeHeaderToLog( SECTION + " Applying the / operator");
61     test();
62
63 function test() {
64     for ( tc=0; tc < testcases.length; tc++ ) {
65         testcases[tc].passed = writeTestCaseResult(
66                             testcases[tc].expect,
67                             testcases[tc].actual,
68                             testcases[tc].description +" = "+
69                             testcases[tc].actual );
70
71         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
72     }
73     stopTest();
74     return ( testcases );
75 }
76 function getTestCases() {
77     var array = new Array();
78     var item = 0;
79
80    // if either operand is NaN, the result is NaN.
81
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 );
85
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 );
88
89     // Division of an infinity by an infinity results in NaN.
90
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 );
95
96     // Division of an infinity by a zero results in an infinity.
97
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 );
102
103     // Division of an infinity by a non-zero finite value results in a signed infinity.
104
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 );
109
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 );
114
115     // Division of a finite value by an infinity results in zero.
116
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 );
121
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 );
126
127     // Division of a zero by a zero results in NaN
128
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 );
133
134     // division of zero by any other finite value results in zero
135
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 );
140
141     // Division of a non-zero finite value by a zero results in a signed infinity.
142
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 );
147
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 );
152
153     return ( array );
154 }