|
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 |
|
7 /** |
|
8 File Name: 11.6.3.js |
|
9 ECMA Section: 11.6.3 Applying the additive operators |
|
10 (+, -) to numbers |
|
11 Description: |
|
12 The + operator performs addition when applied to two operands of numeric |
|
13 type, producing the sum of the operands. The - operator performs |
|
14 subtraction, producing the difference of two numeric operands. |
|
15 |
|
16 Addition is a commutative operation, but not always associative. |
|
17 |
|
18 The result of an addition is determined using the rules of IEEE 754 |
|
19 double-precision arithmetic: |
|
20 |
|
21 If either operand is NaN, the result is NaN. |
|
22 The sum of two infinities of opposite sign is NaN. |
|
23 The sum of two infinities of the same sign is the infinity of that sign. |
|
24 The sum of an infinity and a finite value is equal to the infinite operand. |
|
25 The sum of two negative zeros is 0. The sum of two positive zeros, or of |
|
26 two zeros of opposite sign, is +0. |
|
27 The sum of a zero and a nonzero finite value is equal to the nonzero |
|
28 operand. |
|
29 The sum of two nonzero finite values of the same magnitude and opposite |
|
30 sign is +0. |
|
31 In the remaining cases, where neither an infinity, nor a zero, nor NaN is |
|
32 involved, and the operands have the same sign or have different |
|
33 magnitudes, the sum is computed and rounded to the nearest |
|
34 representable value using IEEE 754 round-to-nearest mode. If the |
|
35 magnitude is too large to represent, the operation overflows and |
|
36 the result is then an infinity of appropriate sign. The ECMAScript |
|
37 language requires support of gradual underflow as defined by IEEE 754. |
|
38 |
|
39 Author: christine@netscape.com |
|
40 Date: 12 november 1997 |
|
41 */ |
|
42 var SECTION = "11.6.3"; |
|
43 var VERSION = "ECMA_1"; |
|
44 startTest(); |
|
45 |
|
46 writeHeaderToLog( SECTION + " Applying the additive operators (+,-) to numbers"); |
|
47 |
|
48 new TestCase( SECTION, "Number.NaN + 1", Number.NaN, Number.NaN + 1 ); |
|
49 new TestCase( SECTION, "1 + Number.NaN", Number.NaN, 1 + Number.NaN ); |
|
50 |
|
51 new TestCase( SECTION, "Number.NaN - 1", Number.NaN, Number.NaN - 1 ); |
|
52 new TestCase( SECTION, "1 - Number.NaN", Number.NaN, 1 - Number.NaN ); |
|
53 |
|
54 new TestCase( SECTION, "Number.POSITIVE_INFINITY + Number.POSITIVE_INFINITY", Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY + Number.POSITIVE_INFINITY); |
|
55 new TestCase( SECTION, "Number.NEGATIVE_INFINITY + Number.NEGATIVE_INFINITY", Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY + Number.NEGATIVE_INFINITY); |
|
56 |
|
57 new TestCase( SECTION, "Number.POSITIVE_INFINITY + Number.NEGATIVE_INFINITY", Number.NaN, Number.POSITIVE_INFINITY + Number.NEGATIVE_INFINITY); |
|
58 new TestCase( SECTION, "Number.NEGATIVE_INFINITY + Number.POSITIVE_INFINITY", Number.NaN, Number.NEGATIVE_INFINITY + Number.POSITIVE_INFINITY); |
|
59 |
|
60 new TestCase( SECTION, "Number.POSITIVE_INFINITY - Number.POSITIVE_INFINITY", Number.NaN, Number.POSITIVE_INFINITY - Number.POSITIVE_INFINITY); |
|
61 new TestCase( SECTION, "Number.NEGATIVE_INFINITY - Number.NEGATIVE_INFINITY", Number.NaN, Number.NEGATIVE_INFINITY - Number.NEGATIVE_INFINITY); |
|
62 |
|
63 new TestCase( SECTION, "Number.POSITIVE_INFINITY - Number.NEGATIVE_INFINITY", Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY - Number.NEGATIVE_INFINITY); |
|
64 new TestCase( SECTION, "Number.NEGATIVE_INFINITY - Number.POSITIVE_INFINITY", Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY - Number.POSITIVE_INFINITY); |
|
65 |
|
66 new TestCase( SECTION, "-0 + -0", -0, -0 + -0 ); |
|
67 new TestCase( SECTION, "-0 - 0", -0, -0 - 0 ); |
|
68 |
|
69 new TestCase( SECTION, "0 + 0", 0, 0 + 0 ); |
|
70 new TestCase( SECTION, "0 + -0", 0, 0 + -0 ); |
|
71 new TestCase( SECTION, "0 - -0", 0, 0 - -0 ); |
|
72 new TestCase( SECTION, "0 - 0", 0, 0 - 0 ); |
|
73 new TestCase( SECTION, "-0 - -0", 0, -0 - -0 ); |
|
74 new TestCase( SECTION, "-0 + 0", 0, -0 + 0 ); |
|
75 |
|
76 new TestCase( SECTION, "Number.MAX_VALUE - Number.MAX_VALUE", 0, Number.MAX_VALUE - Number.MAX_VALUE ); |
|
77 new TestCase( SECTION, "1/Number.MAX_VALUE - 1/Number.MAX_VALUE", 0, 1/Number.MAX_VALUE - 1/Number.MAX_VALUE ); |
|
78 |
|
79 new TestCase( SECTION, "Number.MIN_VALUE - Number.MIN_VALUE", 0, Number.MIN_VALUE - Number.MIN_VALUE ); |
|
80 |
|
81 test(); |