| 1 |
/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ |
| 2 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 |
|
| 6 |
|
| 7 |
/** |
| 8 |
File Name: 15.8.2.18.js |
| 9 |
ECMA Section: 15.8.2.18 tan( x ) |
| 10 |
Description: return an approximation to the tan of the |
| 11 |
argument. argument is expressed in radians |
| 12 |
special cases: |
| 13 |
- if x is NaN result is NaN |
| 14 |
- if x is 0 result is 0 |
| 15 |
- if x is -0 result is -0 |
| 16 |
- if x is Infinity or -Infinity result is NaN |
| 17 |
Author: [email protected] |
| 18 |
Date: 7 july 1997 |
| 19 |
*/ |
| 20 |
|
| 21 |
var SECTION = "15.8.2.18"; |
| 22 |
var TITLE = "Math.tan(x)"; |
| 23 |
var EXCLUDE = "true"; |
| 24 |
|
| 25 |
writeHeaderToLog( SECTION + " "+ TITLE); |
| 26 |
|
| 27 |
new TestCase( "Math.tan.length", |
| 28 |
1, |
| 29 |
Math.tan.length ); |
| 30 |
|
| 31 |
new TestCase( "Math.tan()", |
| 32 |
Number.NaN, |
| 33 |
Math.tan() ); |
| 34 |
|
| 35 |
new TestCase( "Math.tan(void 0)", |
| 36 |
Number.NaN, |
| 37 |
Math.tan(void 0)); |
| 38 |
|
| 39 |
new TestCase( "Math.tan(null)", |
| 40 |
0, |
| 41 |
Math.tan(null) ); |
| 42 |
|
| 43 |
new TestCase( "Math.tan(false)", |
| 44 |
0, |
| 45 |
Math.tan(false) ); |
| 46 |
|
| 47 |
new TestCase( "Math.tan(NaN)", |
| 48 |
Number.NaN, |
| 49 |
Math.tan(Number.NaN) ); |
| 50 |
|
| 51 |
new TestCase( "Math.tan(0)", |
| 52 |
0, |
| 53 |
Math.tan(0)); |
| 54 |
|
| 55 |
new TestCase( "Math.tan(-0)", |
| 56 |
-0, |
| 57 |
Math.tan(-0)); |
| 58 |
|
| 59 |
new TestCase( "Math.tan(Infinity)", |
| 60 |
Number.NaN, |
| 61 |
Math.tan(Number.POSITIVE_INFINITY)); |
| 62 |
|
| 63 |
new TestCase( "Math.tan(-Infinity)", |
| 64 |
Number.NaN, |
| 65 |
Math.tan(Number.NEGATIVE_INFINITY)); |
| 66 |
|
| 67 |
new TestCase( "Math.tan(Math.PI/4)", |
| 68 |
1, |
| 69 |
Math.tan(Math.PI/4)); |
| 70 |
|
| 71 |
new TestCase( "Math.tan(3*Math.PI/4)", |
| 72 |
-1, |
| 73 |
Math.tan(3*Math.PI/4)); |
| 74 |
|
| 75 |
new TestCase( "Math.tan(Math.PI)", |
| 76 |
-0, |
| 77 |
Math.tan(Math.PI)); |
| 78 |
|
| 79 |
new TestCase( "Math.tan(5*Math.PI/4)", |
| 80 |
1, |
| 81 |
Math.tan(5*Math.PI/4)); |
| 82 |
|
| 83 |
new TestCase( "Math.tan(7*Math.PI/4)", |
| 84 |
-1, |
| 85 |
Math.tan(7*Math.PI/4)); |
| 86 |
|
| 87 |
new TestCase( "Infinity/Math.tan(-0)", |
| 88 |
-Infinity, |
| 89 |
Infinity/Math.tan(-0) ); |
| 90 |
|
| 91 |
/* |
| 92 |
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. |
| 93 |
That is to say, perturbing PI/2 by this much is about the smallest rounding error possible. |
| 94 |
|
| 95 |
This suggests that the answer Christine is getting and a real Infinity are "adjacent" results from the tangent function. I |
| 96 |
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 |
| 97 |
results to infinity that the algorithm can deliver. |
| 98 |
|
| 99 |
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. |
| 100 |
= C = |
| 101 |
*/ |
| 102 |
|
| 103 |
new TestCase( "Math.tan(3*Math.PI/2) >= 5443000000000000", |
| 104 |
true, |
| 105 |
Math.tan(3*Math.PI/2) >= 5443000000000000 ); |
| 106 |
|
| 107 |
new TestCase( "Math.tan(Math.PI/2) >= 5443000000000000", |
| 108 |
true, |
| 109 |
Math.tan(Math.PI/2) >= 5443000000000000 ); |
| 110 |
|
| 111 |
test(); |