michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 11.5.2.js michael@0: ECMA Section: 11.5.2 Applying the / operator michael@0: Description: michael@0: michael@0: The / operator performs division, producing the quotient of its operands. michael@0: The left operand is the dividend and the right operand is the divisor. michael@0: ECMAScript does not perform integer division. The operands and result of all michael@0: division operations are double-precision floating-point numbers. michael@0: The result of division is determined by the specification of IEEE 754 arithmetic: michael@0: michael@0: If either operand is NaN, the result is NaN. michael@0: The sign of the result is positive if both operands have the same sign, negative if the operands have different michael@0: signs. michael@0: Division of an infinity by an infinity results in NaN. michael@0: Division of an infinity by a zero results in an infinity. The sign is determined by the rule already stated above. michael@0: Division of an infinity by a non-zero finite value results in a signed infinity. The sign is determined by the rule michael@0: already stated above. michael@0: Division of a finite value by an infinity results in zero. The sign is determined by the rule already stated above. michael@0: Division of a zero by a zero results in NaN; division of zero by any other finite value results in zero, with the sign michael@0: determined by the rule already stated above. michael@0: Division of a non-zero finite value by a zero results in a signed infinity. The sign is determined by the rule michael@0: already stated above. michael@0: In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the quotient is computed and michael@0: rounded to the nearest representable value using IEEE 754 round-to-nearest mode. If the magnitude is too michael@0: large to represent, we say the operation overflows; the result is then an infinity of appropriate sign. If the michael@0: magnitude is too small to represent, we say the operation underflows and the result is a zero of the appropriate michael@0: sign. The ECMAScript language requires support of gradual underflow as defined by IEEE 754. michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: var SECTION = "11.5.2"; michael@0: var VERSION = "ECMA_1"; michael@0: var BUGNUMBER="111202"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " Applying the / operator"); michael@0: michael@0: // if either operand is NaN, the result is NaN. michael@0: michael@0: new TestCase( SECTION, "Number.NaN / Number.NaN", Number.NaN, Number.NaN / Number.NaN ); michael@0: new TestCase( SECTION, "Number.NaN / 1", Number.NaN, Number.NaN / 1 ); michael@0: new TestCase( SECTION, "1 / Number.NaN", Number.NaN, 1 / Number.NaN ); michael@0: michael@0: new TestCase( SECTION, "Number.POSITIVE_INFINITY / Number.NaN", Number.NaN, Number.POSITIVE_INFINITY / Number.NaN ); michael@0: new TestCase( SECTION, "Number.NEGATIVE_INFINITY / Number.NaN", Number.NaN, Number.NEGATIVE_INFINITY / Number.NaN ); michael@0: michael@0: // Division of an infinity by an infinity results in NaN. michael@0: michael@0: new TestCase( SECTION, "Number.NEGATIVE_INFINITY / Number.NEGATIVE_INFINITY", Number.NaN, Number.NEGATIVE_INFINITY / Number.NEGATIVE_INFINITY ); michael@0: new TestCase( SECTION, "Number.POSITIVE_INFINITY / Number.NEGATIVE_INFINITY", Number.NaN, Number.POSITIVE_INFINITY / Number.NEGATIVE_INFINITY ); michael@0: new TestCase( SECTION, "Number.NEGATIVE_INFINITY / Number.POSITIVE_INFINITY", Number.NaN, Number.NEGATIVE_INFINITY / Number.POSITIVE_INFINITY ); michael@0: new TestCase( SECTION, "Number.POSITIVE_INFINITY / Number.POSITIVE_INFINITY", Number.NaN, Number.POSITIVE_INFINITY / Number.POSITIVE_INFINITY ); michael@0: michael@0: // Division of an infinity by a zero results in an infinity. michael@0: michael@0: new TestCase( SECTION, "Number.POSITIVE_INFINITY / 0", Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / 0 ); michael@0: new TestCase( SECTION, "Number.NEGATIVE_INFINITY / 0", Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY / 0 ); michael@0: new TestCase( SECTION, "Number.POSITIVE_INFINITY / -0", Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / -0 ); michael@0: new TestCase( SECTION, "Number.NEGATIVE_INFINITY / -0", Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY / -0 ); michael@0: michael@0: // Division of an infinity by a non-zero finite value results in a signed infinity. michael@0: michael@0: new TestCase( SECTION, "Number.NEGATIVE_INFINITY / 1 ", Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY / 1 ); michael@0: new TestCase( SECTION, "Number.NEGATIVE_INFINITY / -1 ", Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY / -1 ); michael@0: new TestCase( SECTION, "Number.POSITIVE_INFINITY / 1 ", Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / 1 ); michael@0: new TestCase( SECTION, "Number.POSITIVE_INFINITY / -1 ", Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / -1 ); michael@0: michael@0: new TestCase( SECTION, "Number.NEGATIVE_INFINITY / Number.MAX_VALUE ", Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY / Number.MAX_VALUE ); michael@0: new TestCase( SECTION, "Number.NEGATIVE_INFINITY / -Number.MAX_VALUE ", Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY / -Number.MAX_VALUE ); michael@0: new TestCase( SECTION, "Number.POSITIVE_INFINITY / Number.MAX_VALUE ", Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / Number.MAX_VALUE ); michael@0: new TestCase( SECTION, "Number.POSITIVE_INFINITY / -Number.MAX_VALUE ", Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / -Number.MAX_VALUE ); michael@0: michael@0: // Division of a finite value by an infinity results in zero. michael@0: michael@0: new TestCase( SECTION, "1 / Number.NEGATIVE_INFINITY", -0, 1 / Number.NEGATIVE_INFINITY ); michael@0: new TestCase( SECTION, "1 / Number.POSITIVE_INFINITY", 0, 1 / Number.POSITIVE_INFINITY ); michael@0: new TestCase( SECTION, "-1 / Number.POSITIVE_INFINITY", -0, -1 / Number.POSITIVE_INFINITY ); michael@0: new TestCase( SECTION, "-1 / Number.NEGATIVE_INFINITY", 0, -1 / Number.NEGATIVE_INFINITY ); michael@0: michael@0: new TestCase( SECTION, "Number.MAX_VALUE / Number.NEGATIVE_INFINITY", -0, Number.MAX_VALUE / Number.NEGATIVE_INFINITY ); michael@0: new TestCase( SECTION, "Number.MAX_VALUE / Number.POSITIVE_INFINITY", 0, Number.MAX_VALUE / Number.POSITIVE_INFINITY ); michael@0: new TestCase( SECTION, "-Number.MAX_VALUE / Number.POSITIVE_INFINITY", -0, -Number.MAX_VALUE / Number.POSITIVE_INFINITY ); michael@0: new TestCase( SECTION, "-Number.MAX_VALUE / Number.NEGATIVE_INFINITY", 0, -Number.MAX_VALUE / Number.NEGATIVE_INFINITY ); michael@0: michael@0: // Division of a zero by a zero results in NaN michael@0: michael@0: new TestCase( SECTION, "0 / -0", Number.NaN, 0 / -0 ); michael@0: new TestCase( SECTION, "-0 / 0", Number.NaN, -0 / 0 ); michael@0: new TestCase( SECTION, "-0 / -0", Number.NaN, -0 / -0 ); michael@0: new TestCase( SECTION, "0 / 0", Number.NaN, 0 / 0 ); michael@0: michael@0: // division of zero by any other finite value results in zero michael@0: michael@0: new TestCase( SECTION, "0 / 1", 0, 0 / 1 ); michael@0: new TestCase( SECTION, "0 / -1", -0, 0 / -1 ); michael@0: new TestCase( SECTION, "-0 / 1", -0, -0 / 1 ); michael@0: new TestCase( SECTION, "-0 / -1", 0, -0 / -1 ); michael@0: michael@0: // Division of a non-zero finite value by a zero results in a signed infinity. michael@0: michael@0: new TestCase( SECTION, "1 / 0", Number.POSITIVE_INFINITY, 1/0 ); michael@0: new TestCase( SECTION, "1 / -0", Number.NEGATIVE_INFINITY, 1/-0 ); michael@0: new TestCase( SECTION, "-1 / 0", Number.NEGATIVE_INFINITY, -1/0 ); michael@0: new TestCase( SECTION, "-1 / -0", Number.POSITIVE_INFINITY, -1/-0 ); michael@0: michael@0: new TestCase( SECTION, "0 / Number.POSITIVE_INFINITY", 0, 0 / Number.POSITIVE_INFINITY ); michael@0: new TestCase( SECTION, "0 / Number.NEGATIVE_INFINITY", -0, 0 / Number.NEGATIVE_INFINITY ); michael@0: new TestCase( SECTION, "-0 / Number.POSITIVE_INFINITY", -0, -0 / Number.POSITIVE_INFINITY ); michael@0: new TestCase( SECTION, "-0 / Number.NEGATIVE_INFINITY", 0, -0 / Number.NEGATIVE_INFINITY ); michael@0: michael@0: test(); michael@0: