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: var BUGNUMBER = 329383; michael@0: var summary = 'Math copysign issues'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: var inputs = [ michael@0: -Infinity, michael@0: -10.01, michael@0: -9.01, michael@0: -8.01, michael@0: -7.01, michael@0: -6.01, michael@0: -5.01, michael@0: -4.01, michael@0: -Math.PI, michael@0: -3.01, michael@0: -2.01, michael@0: -1.01, michael@0: -0.5, michael@0: -0.49, michael@0: -0.01, michael@0: -0, michael@0: 0, michael@0: +0, michael@0: 0.01, michael@0: 0.49, michael@0: 0.50, michael@0: 0, michael@0: 1.01, michael@0: 2.01, michael@0: 3.01, michael@0: Math.PI, michael@0: 4.01, michael@0: 5.01, michael@0: 6.01, michael@0: 7.01, michael@0: 8.01, michael@0: 9.01, michael@0: 10.01, michael@0: Infinity michael@0: ]; michael@0: michael@0: var iinput; michael@0: michael@0: for (iinput = 0; iinput < inputs.length; iinput++) michael@0: { michael@0: var input = inputs[iinput]; michael@0: reportCompare(Math.round(input), michael@0: emulateRound(input), michael@0: summary + ': Math.round(' + input + ')'); michael@0: } michael@0: michael@0: reportCompare(isNaN(Math.round(NaN)), michael@0: isNaN(emulateRound(NaN)), michael@0: summary + ': Math.round(' + input + ')'); michael@0: michael@0: function emulateRound(x) michael@0: { michael@0: if (!isFinite(x) || x === 0) return x michael@0: if (-0.5 <= x && x < 0) return -0 michael@0: return Math.floor(x + 0.5) michael@0: } michael@0: michael@0: var z; michael@0: michael@0: z = Math.min(-0, 0); michael@0: michael@0: reportCompare(-Math.PI, Math.atan2(z, z), summary + ': Math.atan2(-0, -0)'); michael@0: reportCompare(-Infinity, 1/z, summary + ': 1/-0'); michael@0: michael@0: z = Math.max(-0, 0); michael@0: michael@0: reportCompare(0, Math.atan2(z, z), summary + ': Math.atan2(0, 0)'); michael@0: reportCompare(Infinity, 1/z, summary + ': 1/0');