4
* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
5
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7
* This code is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License version 2 only, as
9
* published by the Free Software Foundation. Oracle designates this
10
* particular file as subject to the "Classpath" exception as provided
11
* by Oracle in the LICENSE file that accompanied this code.
13
* This code is distributed in the hope that it will be useful, but WITHOUT
14
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
* version 2 for more details (a copy is included in the LICENSE file that
17
* accompanied this code).
19
* You should have received a copy of the GNU General Public License version
20
* 2 along with this work; if not, write to the Free Software Foundation,
21
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24
* or visit www.oracle.com if you need additional information or have any
29
* Return tangent function of x.
32
* __kernel_tan ... tangent function on [-pi/4,pi/4]
33
* __ieee754_rem_pio2 ... argument reduction routine
36
* Let S,C and T denote the sin, cos and tan respectively on
37
* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
38
* in [-pi/4 , +pi/4], and let n = k mod 4.
41
* n sin(x) cos(x) tan(x)
42
* ----------------------------------------------------------
47
* ----------------------------------------------------------
50
* Let trig be any of sin, cos, or tan.
51
* trig(+-INF) is NaN, with signals;
52
* trig(NaN) is that NaN;
55
* TRIG(x) returns trig(x) nearly rounded
58
static partial class fdlibm
71
if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
73
/* tan(Inf or NaN) is NaN */
74
else if (ix>=0x7ff00000) return x-x; /* NaN */
76
/* argument reduction needed */
78
double y_0_ = 0.0, y_1_ = 0.0;
79
n = __ieee754_rem_pio2(x, ref y_0_, ref y_1_);
80
return __kernel_tan(y_0_,y_1_,1-((n&1)<<1)); /* 1 -- n even