js/src/tests/ecma/Expressions/11.6.3.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial