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.18.js michael@0: ECMA Section: 15.8.2.18 tan( x ) michael@0: Description: return an approximation to the tan of the michael@0: argument. argument is expressed in radians michael@0: special cases: michael@0: - if x is NaN result is NaN michael@0: - if x is 0 result is 0 michael@0: - if x is -0 result is -0 michael@0: - if x is Infinity or -Infinity result is NaN michael@0: Author: christine@netscape.com michael@0: Date: 7 july 1997 michael@0: */ michael@0: michael@0: var SECTION = "15.8.2.18"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var TITLE = "Math.tan(x)"; michael@0: var EXCLUDE = "true"; michael@0: michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan.length", michael@0: 1, michael@0: Math.tan.length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan()", michael@0: Number.NaN, michael@0: Math.tan() ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(void 0)", michael@0: Number.NaN, michael@0: Math.tan(void 0)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(null)", michael@0: 0, michael@0: Math.tan(null) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(false)", michael@0: 0, michael@0: Math.tan(false) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(NaN)", michael@0: Number.NaN, michael@0: Math.tan(Number.NaN) ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(0)", michael@0: 0, michael@0: Math.tan(0)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(-0)", michael@0: -0, michael@0: Math.tan(-0)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(Infinity)", michael@0: Number.NaN, michael@0: Math.tan(Number.POSITIVE_INFINITY)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(-Infinity)", michael@0: Number.NaN, michael@0: Math.tan(Number.NEGATIVE_INFINITY)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(Math.PI/4)", michael@0: 1, michael@0: Math.tan(Math.PI/4)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(3*Math.PI/4)", michael@0: -1, michael@0: Math.tan(3*Math.PI/4)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(Math.PI)", michael@0: -0, michael@0: Math.tan(Math.PI)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(5*Math.PI/4)", michael@0: 1, michael@0: Math.tan(5*Math.PI/4)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(7*Math.PI/4)", michael@0: -1, michael@0: Math.tan(7*Math.PI/4)); michael@0: michael@0: new TestCase( SECTION, michael@0: "Infinity/Math.tan(-0)", michael@0: -Infinity, michael@0: Infinity/Math.tan(-0) ); michael@0: michael@0: /* michael@0: Arctan (x) ~ PI/2 - 1/x for large x. For x = 1.6x10^16, 1/x is about the last binary digit of double precision PI/2. michael@0: That is to say, perturbing PI/2 by this much is about the smallest rounding error possible. michael@0: michael@0: This suggests that the answer Christine is getting and a real Infinity are "adjacent" results from the tangent function. I michael@0: suspect that tan (PI/2 + one ulp) is a negative result about the same size as tan (PI/2) and that this pair are the closest michael@0: results to infinity that the algorithm can deliver. michael@0: michael@0: In any case, my call is that the answer we're seeing is "right". I suggest the test pass on any result this size or larger. michael@0: = C = michael@0: */ michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(3*Math.PI/2) >= 5443000000000000", michael@0: true, michael@0: Math.tan(3*Math.PI/2) >= 5443000000000000 ); michael@0: michael@0: new TestCase( SECTION, michael@0: "Math.tan(Math.PI/2) >= 5443000000000000", michael@0: true, michael@0: Math.tan(Math.PI/2) >= 5443000000000000 ); michael@0: michael@0: test();