Home | History | Annotate | Download | only in Expressions
      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/
      5  *
      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.
     10  *
     11  * The Original Code is Mozilla Communicator client code, released March
     12  * 31, 1998.
     13  *
     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
     17  * Rights Reserved.
     18  *
     19  * Contributor(s):
     20  *
     21  */
     22 /**
     23     File Name:          11.6.3.js
     24     ECMA Section:       11.6.3 Applying the additive operators
     25                         (+, -) to numbers
     26     Description:
     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.
     30 
     31     Addition is a commutative operation, but not always associative.
     32 
     33     The result of an addition is determined using the rules of IEEE 754
     34     double-precision arithmetic:
     35 
     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
     43         operand.
     44       The sum of two nonzero finite values of the same magnitude and opposite
     45         sign is +0.
     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.
     53 
     54     Author:             christine (at) netscape.com
     55     Date:               12 november 1997
     56 */
     57     var SECTION = "11.6.3";
     58     var VERSION = "ECMA_1";
     59     startTest();
     60     var testcases = getTestCases();
     61 
     62     writeHeaderToLog( SECTION + " Applying the additive operators (+,-) to numbers");
     63     test();
     64 
     65 function test() {
     66     for ( tc=0; tc < testcases.length; tc++ ) {
     67         testcases[tc].passed = writeTestCaseResult(
     68                             testcases[tc].expect,
     69                             testcases[tc].actual,
     70                             testcases[tc].description +" = "+
     71                             testcases[tc].actual );
     72 
     73         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
     74     }
     75     stopTest();
     76     return ( testcases );
     77 }
     78 function getTestCases() {
     79     var array = new Array();
     80     var item = 0;
     81 
     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 );
     84 
     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 );
     87 
     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);
     90 
     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);
     93 
     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);
     96 
     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);
     99 
    100     array[item++] = new TestCase( SECTION,  "-0 + -0",      -0,     -0 + -0 );
    101     array[item++] = new TestCase( SECTION,  "-0 - 0",       -0,     -0 - 0 );
    102 
    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 );
    109 
    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 );
    112 
    113     array[item++] = new TestCase( SECTION,  "Number.MIN_VALUE - Number.MIN_VALUE",      0,  Number.MIN_VALUE - Number.MIN_VALUE );
    114 
    115     return ( array );
    116 }
    117