]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Expressions/11.6.3.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.6.3 Applying the additive operators
27 The + operator performs addition when applied to two operands of numeric
28 type, producing the sum of the operands. The - operator performs
29 subtraction, producing the difference of two numeric operands.
31 Addition is a commutative operation, but not always associative.
33 The result of an addition is determined using the rules of IEEE 754
34 double-precision arithmetic:
36 If either operand is NaN, the result is NaN.
37 The sum of two infinities of opposite sign is NaN.
38 The sum of two infinities of the same sign is the infinity of that sign.
39 The sum of an infinity and a finite value is equal to the infinite operand.
40 The sum of two negative zeros is 0. The sum of two positive zeros, or of
41 two zeros of opposite sign, is +0.
42 The sum of a zero and a nonzero finite value is equal to the nonzero
44 The sum of two nonzero finite values of the same magnitude and opposite
46 In the remaining cases, where neither an infinity, nor a zero, nor NaN is
47 involved, and the operands have the same sign or have different
48 magnitudes, the sum is computed and rounded to the nearest
49 representable value using IEEE 754 round-to-nearest mode. If the
50 magnitude is too large to represent, the operation overflows and
51 the result is then an infinity of appropriate sign. The ECMAScript
52 language requires support of gradual underflow as defined by IEEE 754.
54 Author: christine@netscape.com
55 Date: 12 november 1997
57 var SECTION
= "11.6.3";
58 var VERSION
= "ECMA_1";
60 var testcases
= getTestCases();
62 writeHeaderToLog( SECTION
+ " Applying the additive operators (+,-) to numbers");
66 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
67 testcases
[tc
].passed
= writeTestCaseResult(
70 testcases
[tc
].description
+" = "+
71 testcases
[tc
].actual
);
73 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
78 function getTestCases() {
79 var array
= new Array();
82 array
[item
++] = new TestCase( SECTION
, "Number.NaN + 1", Number
.NaN
, Number
.NaN
+ 1 );
83 array
[item
++] = new TestCase( SECTION
, "1 + Number.NaN", Number
.NaN
, 1 + Number
.NaN
);
85 array
[item
++] = new TestCase( SECTION
, "Number.NaN - 1", Number
.NaN
, Number
.NaN
- 1 );
86 array
[item
++] = new TestCase( SECTION
, "1 - Number.NaN", Number
.NaN
, 1 - Number
.NaN
);
88 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY + Number.POSITIVE_INFINITY", Number
.POSITIVE_INFINITY
, Number
.POSITIVE_INFINITY
+ Number
.POSITIVE_INFINITY
);
89 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY + Number.NEGATIVE_INFINITY", Number
.NEGATIVE_INFINITY
, Number
.NEGATIVE_INFINITY
+ Number
.NEGATIVE_INFINITY
);
91 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY + Number.NEGATIVE_INFINITY", Number
.NaN
, Number
.POSITIVE_INFINITY
+ Number
.NEGATIVE_INFINITY
);
92 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 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY - Number.NEGATIVE_INFINITY", Number
.NaN
, Number
.NEGATIVE_INFINITY
- Number
.NEGATIVE_INFINITY
);
97 array
[item
++] = new TestCase( SECTION
, "Number.POSITIVE_INFINITY - Number.NEGATIVE_INFINITY", Number
.POSITIVE_INFINITY
, Number
.POSITIVE_INFINITY
- Number
.NEGATIVE_INFINITY
);
98 array
[item
++] = new TestCase( SECTION
, "Number.NEGATIVE_INFINITY - Number.POSITIVE_INFINITY", Number
.NEGATIVE_INFINITY
, Number
.NEGATIVE_INFINITY
- Number
.POSITIVE_INFINITY
);
100 array
[item
++] = new TestCase( SECTION
, "-0 + -0", -0, -0 + -0 );
101 array
[item
++] = new TestCase( SECTION
, "-0 - 0", -0, -0 - 0 );
103 array
[item
++] = new TestCase( SECTION
, "0 + 0", 0, 0 + 0 );
104 array
[item
++] = new TestCase( SECTION
, "0 + -0", 0, 0 + -0 );
105 array
[item
++] = new TestCase( SECTION
, "0 - -0", 0, 0 - -0 );
106 array
[item
++] = new TestCase( SECTION
, "0 - 0", 0, 0 - 0 );
107 array
[item
++] = new TestCase( SECTION
, "-0 - -0", 0, -0 - -0 );
108 array
[item
++] = new TestCase( SECTION
, "-0 + 0", 0, -0 + 0 );
110 array
[item
++] = new TestCase( SECTION
, "Number.MAX_VALUE - Number.MAX_VALUE", 0, Number
.MAX_VALUE
- Number
.MAX_VALUE
);
111 array
[item
++] = new TestCase( SECTION
, "1/Number.MAX_VALUE - 1/Number.MAX_VALUE", 0, 1/Number
.MAX_VALUE
- 1/Number
.MAX_VALUE
);
113 array
[item
++] = new TestCase( SECTION
, "Number.MIN_VALUE - Number.MIN_VALUE", 0, Number
.MIN_VALUE
- Number
.MIN_VALUE
);