Debian Codegraph @

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