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: 15.8.2.1.js michael@0: ECMA Section: 15.8.2.1 abs( x ) michael@0: Description: return the absolute value of the argument, michael@0: which should be the magnitude of the argument michael@0: with a positive sign. michael@0: - if x is NaN, return NaN michael@0: - if x is -0, result is +0 michael@0: - if x is -Infinity, result is +Infinity michael@0: Author: christine@netscape.com michael@0: Date: 7 july 1997 michael@0: */ michael@0: var SECTION = "15.8.2.1"; michael@0: var VERSION = "ECMA_1"; michael@0: var TITLE = "Math.abs()"; michael@0: var BUGNUMBER = "77391"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs.length", michael@0: 1, michael@0: Math.abs.length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs()", michael@0: Number.NaN, michael@0: Math.abs() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( void 0 )", michael@0: Number.NaN, michael@0: Math.abs(void 0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( null )", michael@0: 0, michael@0: Math.abs(null) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( true )", michael@0: 1, michael@0: Math.abs(true) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( false )", michael@0: 0, michael@0: Math.abs(false) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( string primitive)", michael@0: Number.NaN, michael@0: Math.abs("a string primitive") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( string object )", michael@0: Number.NaN, michael@0: Math.abs(new String( 'a String object' )) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( Number.NaN )", michael@0: Number.NaN, michael@0: Math.abs(Number.NaN) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs(0)", michael@0: 0, michael@0: Math.abs( 0 ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( -0 )", michael@0: 0, michael@0: Math.abs(-0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Infinity/Math.abs(-0)", michael@0: Infinity, michael@0: Infinity/Math.abs(-0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( -Infinity )", michael@0: Number.POSITIVE_INFINITY, michael@0: Math.abs( Number.NEGATIVE_INFINITY ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( Infinity )", michael@0: Number.POSITIVE_INFINITY, michael@0: Math.abs( Number.POSITIVE_INFINITY ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( - MAX_VALUE )", michael@0: Number.MAX_VALUE, michael@0: Math.abs( - Number.MAX_VALUE ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( - MIN_VALUE )", michael@0: Number.MIN_VALUE, michael@0: Math.abs( -Number.MIN_VALUE ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( MAX_VALUE )", michael@0: Number.MAX_VALUE, michael@0: Math.abs( Number.MAX_VALUE ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( MIN_VALUE )", michael@0: Number.MIN_VALUE, michael@0: Math.abs( Number.MIN_VALUE ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( -1 )", michael@0: 1, michael@0: Math.abs( -1 ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( new Number( -1 ) )", michael@0: 1, michael@0: Math.abs( new Number(-1) ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( 1 )", michael@0: 1, michael@0: Math.abs( 1 ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( Math.PI )", michael@0: Math.PI, michael@0: Math.abs( Math.PI ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( -Math.PI )", michael@0: Math.PI, michael@0: Math.abs( -Math.PI ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs(-1/100000000)", michael@0: 1/100000000, michael@0: Math.abs(-1/100000000) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs(-Math.pow(2,32))", michael@0: Math.pow(2,32), michael@0: Math.abs(-Math.pow(2,32)) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs(Math.pow(2,32))", michael@0: Math.pow(2,32), michael@0: Math.abs(Math.pow(2,32)) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( -0xfff )", michael@0: 4095, michael@0: Math.abs( -0xfff ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( -0777 )", michael@0: 511, michael@0: Math.abs(-0777 ) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs('-1e-1')", michael@0: 0.1, michael@0: Math.abs('-1e-1') ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs('0xff')", michael@0: 255, michael@0: Math.abs('0xff') ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs('077')", michael@0: 77, michael@0: Math.abs('077') ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( 'Infinity' )", michael@0: Infinity, michael@0: Math.abs('Infinity') ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.abs( '-Infinity' )", michael@0: Infinity, michael@0: Math.abs('-Infinity') ); michael@0: michael@0: test();