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.15.js michael@0: ECMA Section: 15.8.2.15 Math.round(x) michael@0: Description: return the greatest number value that is closest to the michael@0: argument and is an integer. if two integers are equally michael@0: close to the argument. then the result is the number value michael@0: that is closer to Infinity. if the argument is an integer, michael@0: return the argument. michael@0: special cases: michael@0: - if x is NaN return NaN michael@0: - if x = +0 return +0 michael@0: - if x = -0 return -0 michael@0: - if x = Infinity return Infinity michael@0: - if x = -Infinity return -Infinity michael@0: - if 0 < x < 0.5 return 0 michael@0: - if -0.5 <= x < 0 return -0 michael@0: example: michael@0: Math.round( 3.5 ) == 4 michael@0: Math.round( -3.5 ) == 3 michael@0: also: michael@0: - Math.round(x) == Math.floor( x + 0.5 ) michael@0: except if x = -0. in that case, Math.round(x) = -0 michael@0: michael@0: and Math.floor( x+0.5 ) = +0 michael@0: michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 7 july 1997 michael@0: */ michael@0: michael@0: var SECTION = "15.8.2.15"; michael@0: var VERSION = "ECMA_1"; michael@0: var TITLE = "Math.round(x)"; michael@0: var BUGNUMBER="331411"; michael@0: michael@0: var EXCLUDE = "true"; michael@0: michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round.length", michael@0: 1, michael@0: Math.round.length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round()", michael@0: Number.NaN, michael@0: Math.round() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(null)", michael@0: 0, michael@0: Math.round(0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(void 0)", michael@0: Number.NaN, michael@0: Math.round(void 0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(true)", michael@0: 1, michael@0: Math.round(true) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(false)", michael@0: 0, michael@0: Math.round(false) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round('.99999')", michael@0: 1, michael@0: Math.round('.99999') ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round('12345e-2')", michael@0: 123, michael@0: Math.round('12345e-2') ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(NaN)", michael@0: Number.NaN, michael@0: Math.round(Number.NaN) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(0)", michael@0: 0, michael@0: Math.round(0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(-0)", michael@0: -0, michael@0: Math.round(-0)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Infinity/Math.round(-0)", michael@0: -Infinity, michael@0: Infinity/Math.round(-0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(Infinity)", michael@0: Number.POSITIVE_INFINITY, michael@0: Math.round(Number.POSITIVE_INFINITY)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(-Infinity)", michael@0: Number.NEGATIVE_INFINITY, michael@0: Math.round(Number.NEGATIVE_INFINITY)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(0.49)", michael@0: 0, michael@0: Math.round(0.49)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(0.5)", michael@0: 1, michael@0: Math.round(0.5)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(0.51)", michael@0: 1, michael@0: Math.round(0.51)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(-0.49)", michael@0: -0, michael@0: Math.round(-0.49)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(-0.5)", michael@0: -0, michael@0: Math.round(-0.5)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Infinity/Math.round(-0.49)", michael@0: -Infinity, michael@0: Infinity/Math.round(-0.49)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Infinity/Math.round(-0.5)", michael@0: -Infinity, michael@0: Infinity/Math.round(-0.5)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(-0.51)", michael@0: -1, michael@0: Math.round(-0.51)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(3.5)", michael@0: 4, michael@0: Math.round(3.5)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.round(-3.5)", michael@0: -3, michael@0: Math.round(-3)); michael@0: michael@0: test();