1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 File Name: 15.8.2.18.js
42 ECMA Section: 15.8.2.18 tan( x )
43 Description: return an approximation to the tan of the
44 argument. argument is expressed in radians
46 - if x is NaN result is NaN
47 - if x is 0 result is 0
48 - if x is -0 result is -0
49 - if x is Infinity or -Infinity result is NaN
50 Author: christine@netscape.com
54 var SECTION = "15.8.2.18";
55 var VERSION = "ECMA_1";
57 var TITLE = "Math.tan(x)";
60 writeHeaderToLog( SECTION + " "+ TITLE);
62 new TestCase( SECTION,
67 new TestCase( SECTION,
72 new TestCase( SECTION,
77 new TestCase( SECTION,
82 new TestCase( SECTION,
87 new TestCase( SECTION,
90 Math.tan(Number.NaN) );
92 new TestCase( SECTION,
97 new TestCase( SECTION,
102 new TestCase( SECTION,
103 "Math.tan(Infinity)",
105 Math.tan(Number.POSITIVE_INFINITY));
107 new TestCase( SECTION,
108 "Math.tan(-Infinity)",
110 Math.tan(Number.NEGATIVE_INFINITY));
112 new TestCase( SECTION,
113 "Math.tan(Math.PI/4)",
115 Math.tan(Math.PI/4));
117 new TestCase( SECTION,
118 "Math.tan(3*Math.PI/4)",
120 Math.tan(3*Math.PI/4));
122 new TestCase( SECTION,
127 new TestCase( SECTION,
128 "Math.tan(5*Math.PI/4)",
130 Math.tan(5*Math.PI/4));
132 new TestCase( SECTION,
133 "Math.tan(7*Math.PI/4)",
135 Math.tan(7*Math.PI/4));
137 new TestCase( SECTION,
138 "Infinity/Math.tan(-0)",
140 Infinity/Math.tan(-0) );
143 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.
144 That is to say, perturbing PI/2 by this much is about the smallest rounding error possible.
146 This suggests that the answer Christine is getting and a real Infinity are "adjacent" results from the tangent function. I
147 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
148 results to infinity that the algorithm can deliver.
150 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.
154 new TestCase( SECTION,
155 "Math.tan(3*Math.PI/2) >= 5443000000000000",
157 Math.tan(3*Math.PI/2) >= 5443000000000000 );
159 new TestCase( SECTION,
160 "Math.tan(Math.PI/2) >= 5443000000000000",
162 Math.tan(Math.PI/2) >= 5443000000000000 );