1/* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
5 *
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
23    File Name:          15.8.2.18.js
24    ECMA Section:       15.8.2.18 tan( x )
25    Description:        return an approximation to the tan of the
26                        argument.  argument is expressed in radians
27                        special cases:
28                        - if x is NaN           result is NaN
29                        - if x is 0             result is 0
30                        - if x is -0            result is -0
31                        - if x is Infinity or -Infinity result is NaN
32    Author:             christine@netscape.com
33    Date:               7 july 1997
34*/
35
36    var SECTION = "15.8.2.18";
37    var VERSION = "ECMA_1";
38    startTest();
39    var TITLE   = "Math.tan(x)";
40    var EXCLUDE = "true";
41
42    writeHeaderToLog( SECTION + " "+ TITLE);
43
44    var testcases = getTestCases();
45    test();
46
47function getTestCases() {
48    var array = new Array();
49    var item = 0;
50
51    array[item++] = new TestCase( SECTION,  "Math.tan.length",          1,              Math.tan.length );
52
53    array[item++] = new TestCase( SECTION,  "Math.tan()",               Number.NaN,      Math.tan() );
54    array[item++] = new TestCase( SECTION,  "Math.tan(void 0)",         Number.NaN,     Math.tan(void 0));
55    array[item++] = new TestCase( SECTION,  "Math.tan(null)",           0,              Math.tan(null) );
56    array[item++] = new TestCase( SECTION,  "Math.tan(false)",          0,              Math.tan(false) );
57
58    array[item++] = new TestCase( SECTION,  "Math.tan(NaN)",            Number.NaN,     Math.tan(Number.NaN) );
59    array[item++] = new TestCase( SECTION,  "Math.tan(0)",              0,	            Math.tan(0));
60    array[item++] = new TestCase( SECTION,  "Math.tan(-0)",             -0,         	Math.tan(-0));
61    array[item++] = new TestCase( SECTION,  "Math.tan(Infinity)",       Number.NaN,     Math.tan(Number.POSITIVE_INFINITY));
62    array[item++] = new TestCase( SECTION,  "Math.tan(-Infinity)",      Number.NaN,     Math.tan(Number.NEGATIVE_INFINITY));
63    array[item++] = new TestCase( SECTION,  "Math.tan(Math.PI/4)",      1,              Math.tan(Math.PI/4));
64    array[item++] = new TestCase( SECTION,  "Math.tan(3*Math.PI/4)",    -1,             Math.tan(3*Math.PI/4));
65    array[item++] = new TestCase( SECTION,  "Math.tan(Math.PI)",        -0,             Math.tan(Math.PI));
66    array[item++] = new TestCase( SECTION,  "Math.tan(5*Math.PI/4)",    1,              Math.tan(5*Math.PI/4));
67    array[item++] = new TestCase( SECTION,  "Math.tan(7*Math.PI/4)",    -1,             Math.tan(7*Math.PI/4));
68    array[item++] = new TestCase( SECTION,  "Infinity/Math.tan(-0)",    -Infinity,      Infinity/Math.tan(-0) );
69
70/*
71    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.
72    That is to say, perturbing PI/2 by this much is about the smallest rounding error possible.
73
74    This suggests that the answer Christine is getting and a real Infinity are "adjacent" results from the tangent function.  I
75    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
76    results to infinity that the algorithm can deliver.
77
78    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.
79    = C =
80*/
81    array[item++] = new TestCase( SECTION,  "Math.tan(3*Math.PI/2) >= 5443000000000000",   true,   Math.tan(3*Math.PI/2) >= 5443000000000000 );
82    array[item++] = new TestCase( SECTION,  "Math.tan(Math.PI/2) >= 5443000000000000",      true,   Math.tan(Math.PI/2) >= 5443000000000000 );
83
84    return ( array );
85}
86function test() {
87    for ( tc=0; tc < testcases.length; tc++ ) {
88        testcases[tc].passed = writeTestCaseResult(
89                            testcases[tc].expect,
90                            testcases[tc].actual,
91                            testcases[tc].description +" = "+
92                            testcases[tc].actual );
93
94        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
95    }
96    stopTest();
97    return ( testcases );
98}
99