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.9.js michael@0: ECMA Section: 15.8.2.9 Math.floor(x) michael@0: Description: return the greatest number value that is not greater michael@0: than the argument and is equal to a mathematical integer. michael@0: if the number is already an integer, return the number michael@0: itself. 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 ( -1 < x < 0 ) return -0 michael@0: also: michael@0: - the value of Math.floor(x) == -Math.ceil(-x) michael@0: Author: christine@netscape.com michael@0: Date: 7 july 1997 michael@0: */ michael@0: michael@0: var SECTION = "15.8.2.9"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "Math.floor(x)"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor.length", michael@0: 1, michael@0: Math.floor.length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor()", michael@0: Number.NaN, michael@0: Math.floor() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(void 0)", michael@0: Number.NaN, michael@0: Math.floor(void 0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(null)", michael@0: 0, michael@0: Math.floor(null) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(true)", michael@0: 1, michael@0: Math.floor(true) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(false)", michael@0: 0, michael@0: Math.floor(false) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor('1.1')", michael@0: 1, michael@0: Math.floor("1.1") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor('-1.1')", michael@0: -2, michael@0: Math.floor("-1.1") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor('0.1')", michael@0: 0, michael@0: Math.floor("0.1") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor('-0.1')", michael@0: -1, michael@0: Math.floor("-0.1") ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(NaN)", michael@0: Number.NaN, michael@0: Math.floor(Number.NaN) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(NaN)==-Math.ceil(-NaN)", michael@0: false, michael@0: Math.floor(Number.NaN) == -Math.ceil(-Number.NaN) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(0)", michael@0: 0, michael@0: Math.floor(0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(0)==-Math.ceil(-0)", michael@0: true, michael@0: Math.floor(0) == -Math.ceil(-0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(-0)", michael@0: -0, michael@0: Math.floor(-0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Infinity/Math.floor(-0)", michael@0: -Infinity, michael@0: Infinity/Math.floor(-0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(-0)==-Math.ceil(0)", michael@0: true, michael@0: Math.floor(-0)== -Math.ceil(0) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(Infinity)", michael@0: Number.POSITIVE_INFINITY, michael@0: Math.floor(Number.POSITIVE_INFINITY) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(Infinity)==-Math.ceil(-Infinity)", michael@0: true, michael@0: Math.floor(Number.POSITIVE_INFINITY) == -Math.ceil(Number.NEGATIVE_INFINITY) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(-Infinity)", michael@0: Number.NEGATIVE_INFINITY, michael@0: Math.floor(Number.NEGATIVE_INFINITY) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(-Infinity)==-Math.ceil(Infinity)", michael@0: true, michael@0: Math.floor(Number.NEGATIVE_INFINITY) == -Math.ceil(Number.POSITIVE_INFINITY) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(0.0000001)", michael@0: 0, michael@0: Math.floor(0.0000001) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(0.0000001)==-Math.ceil(0.0000001)", true, michael@0: Math.floor(0.0000001)==-Math.ceil(-0.0000001) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(-0.0000001)", michael@0: -1, michael@0: Math.floor(-0.0000001) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.floor(0.0000001)==-Math.ceil(0.0000001)", michael@0: true, michael@0: Math.floor(-0.0000001)==-Math.ceil(0.0000001) ); michael@0: michael@0: test();