Debian Codegraph @

rhino/testsrc/tests/ecma/Expressions/11.5.2.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = '11.5.2.js';
7
8 /**
9 File Name: 11.5.2.js
10 ECMA Section: 11.5.2 Applying the / operator
11 Description:
12
13 The / operator performs division, producing the quotient of its operands.
14 The left operand is the dividend and the right operand is the divisor.
15 ECMAScript does not perform integer division. The operands and result of all
16 division operations are double-precision floating-point numbers.
17 The result of division is determined by the specification of IEEE 754 arithmetic:
18
19 If either operand is NaN, the result is NaN.
20 The sign of the result is positive if both operands have the same sign, negative if the operands have different
21 signs.
22 Division of an infinity by an infinity results in NaN.
23 Division of an infinity by a zero results in an infinity. The sign is determined by the rule already stated above.
24 Division of an infinity by a non-zero finite value results in a signed infinity. The sign is determined by the rule
25 already stated above.
26 Division of a finite value by an infinity results in zero. The sign is determined by the rule already stated above.
27 Division of a zero by a zero results in NaN; division of zero by any other finite value results in zero, with the sign
28 determined by the rule already stated above.
29 Division of a non-zero finite value by a zero results in a signed infinity. The sign is determined by the rule
30 already stated above.
31 In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the quotient is computed and
32 rounded to the nearest representable value using IEEE 754 round-to-nearest mode. If the magnitude is too
33 large to represent, we say the operation overflows; the result is then an infinity of appropriate sign. If the
34 magnitude is too small to represent, we say the operation underflows and the result is a zero of the appropriate
35 sign. The ECMAScript language requires support of gradual underflow as defined by IEEE 754.
36
37 Author: [email protected]
38 Date: 12 november 1997
39 */
40 var SECTION = "11.5.2";
41 var VERSION = "ECMA_1";
42 var BUGNUMBER="111202";
43 startTest();
44
45 writeHeaderToLog( SECTION + " Applying the / operator");
46
47 // if either operand is NaN, the result is NaN.
48
49 new TestCase( SECTION, "Number.NaN / Number.NaN", Number.NaN, Number.NaN / Number.NaN );
50 new TestCase( SECTION, "Number.NaN / 1", Number.NaN, Number.NaN / 1 );
51 new TestCase( SECTION, "1 / Number.NaN", Number.NaN, 1 / Number.NaN );
52
53 new TestCase( SECTION, "Number.POSITIVE_INFINITY / Number.NaN", Number.NaN, Number.POSITIVE_INFINITY / Number.NaN );
54 new TestCase( SECTION, "Number.NEGATIVE_INFINITY / Number.NaN", Number.NaN, Number.NEGATIVE_INFINITY / Number.NaN );
55
56 // Division of an infinity by an infinity results in NaN.
57
58 new TestCase( SECTION, "Number.NEGATIVE_INFINITY / Number.NEGATIVE_INFINITY", Number.NaN, Number.NEGATIVE_INFINITY / Number.NEGATIVE_INFINITY );
59 new TestCase( SECTION, "Number.POSITIVE_INFINITY / Number.NEGATIVE_INFINITY", Number.NaN, Number.POSITIVE_INFINITY / Number.NEGATIVE_INFINITY );
60 new TestCase( SECTION, "Number.NEGATIVE_INFINITY / Number.POSITIVE_INFINITY", Number.NaN, Number.NEGATIVE_INFINITY / Number.POSITIVE_INFINITY );
61 new TestCase( SECTION, "Number.POSITIVE_INFINITY / Number.POSITIVE_INFINITY", Number.NaN, Number.POSITIVE_INFINITY / Number.POSITIVE_INFINITY );
62
63 // Division of an infinity by a zero results in an infinity.
64
65 new TestCase( SECTION, "Number.POSITIVE_INFINITY / 0", Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / 0 );
66 new TestCase( SECTION, "Number.NEGATIVE_INFINITY / 0", Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY / 0 );
67 new TestCase( SECTION, "Number.POSITIVE_INFINITY / -0", Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / -0 );
68 new TestCase( SECTION, "Number.NEGATIVE_INFINITY / -0", Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY / -0 );
69
70 // Division of an infinity by a non-zero finite value results in a signed infinity.
71
72 new TestCase( SECTION, "Number.NEGATIVE_INFINITY / 1 ", Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY / 1 );
73 new TestCase( SECTION, "Number.NEGATIVE_INFINITY / -1 ", Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY / -1 );
74 new TestCase( SECTION, "Number.POSITIVE_INFINITY / 1 ", Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / 1 );
75 new TestCase( SECTION, "Number.POSITIVE_INFINITY / -1 ", Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / -1 );
76
77 new TestCase( SECTION, "Number.NEGATIVE_INFINITY / Number.MAX_VALUE ", Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY / Number.MAX_VALUE );
78 new TestCase( SECTION, "Number.NEGATIVE_INFINITY / -Number.MAX_VALUE ", Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY / -Number.MAX_VALUE );
79 new TestCase( SECTION, "Number.POSITIVE_INFINITY / Number.MAX_VALUE ", Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / Number.MAX_VALUE );
80 new TestCase( SECTION, "Number.POSITIVE_INFINITY / -Number.MAX_VALUE ", Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / -Number.MAX_VALUE );
81
82 // Division of a finite value by an infinity results in zero.
83
84 new TestCase( SECTION, "1 / Number.NEGATIVE_INFINITY", -0, 1 / Number.NEGATIVE_INFINITY );
85 new TestCase( SECTION, "1 / Number.POSITIVE_INFINITY", 0, 1 / Number.POSITIVE_INFINITY );
86 new TestCase( SECTION, "-1 / Number.POSITIVE_INFINITY", -0, -1 / Number.POSITIVE_INFINITY );
87 new TestCase( SECTION, "-1 / Number.NEGATIVE_INFINITY", 0, -1 / Number.NEGATIVE_INFINITY );
88
89 new TestCase( SECTION, "Number.MAX_VALUE / Number.NEGATIVE_INFINITY", -0, Number.MAX_VALUE / Number.NEGATIVE_INFINITY );
90 new TestCase( SECTION, "Number.MAX_VALUE / Number.POSITIVE_INFINITY", 0, Number.MAX_VALUE / Number.POSITIVE_INFINITY );
91 new TestCase( SECTION, "-Number.MAX_VALUE / Number.POSITIVE_INFINITY", -0, -Number.MAX_VALUE / Number.POSITIVE_INFINITY );
92 new TestCase( SECTION, "-Number.MAX_VALUE / Number.NEGATIVE_INFINITY", 0, -Number.MAX_VALUE / Number.NEGATIVE_INFINITY );
93
94 // Division of a zero by a zero results in NaN
95
96 new TestCase( SECTION, "0 / -0", Number.NaN, 0 / -0 );
97 new TestCase( SECTION, "-0 / 0", Number.NaN, -0 / 0 );
98 new TestCase( SECTION, "-0 / -0", Number.NaN, -0 / -0 );
99 new TestCase( SECTION, "0 / 0", Number.NaN, 0 / 0 );
100
101 // division of zero by any other finite value results in zero
102
103 new TestCase( SECTION, "0 / 1", 0, 0 / 1 );
104 new TestCase( SECTION, "0 / -1", -0, 0 / -1 );
105 new TestCase( SECTION, "-0 / 1", -0, -0 / 1 );
106 new TestCase( SECTION, "-0 / -1", 0, -0 / -1 );
107
108 // Division of a non-zero finite value by a zero results in a signed infinity.
109
110 new TestCase( SECTION, "1 / 0", Number.POSITIVE_INFINITY, 1/0 );
111 new TestCase( SECTION, "1 / -0", Number.NEGATIVE_INFINITY, 1/-0 );
112 new TestCase( SECTION, "-1 / 0", Number.NEGATIVE_INFINITY, -1/0 );
113 new TestCase( SECTION, "-1 / -0", Number.POSITIVE_INFINITY, -1/-0 );
114
115 new TestCase( SECTION, "0 / Number.POSITIVE_INFINITY", 0, 0 / Number.POSITIVE_INFINITY );
116 new TestCase( SECTION, "0 / Number.NEGATIVE_INFINITY", -0, 0 / Number.NEGATIVE_INFINITY );
117 new TestCase( SECTION, "-0 / Number.POSITIVE_INFINITY", -0, -0 / Number.POSITIVE_INFINITY );
118 new TestCase( SECTION, "-0 / Number.NEGATIVE_INFINITY", 0, -0 / Number.NEGATIVE_INFINITY );
119
120 test();
121