Path: blob/master/src/java.base/share/native/libfdlibm/s_tan.c
41152 views
/*1* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/* tan(x)26* Return tangent function of x.27*28* kernel function:29* __kernel_tan ... tangent function on [-pi/4,pi/4]30* __ieee754_rem_pio2 ... argument reduction routine31*32* Method.33* Let S,C and T denote the sin, cos and tan respectively on34* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/235* in [-pi/4 , +pi/4], and let n = k mod 4.36* We have37*38* n sin(x) cos(x) tan(x)39* ----------------------------------------------------------40* 0 S C T41* 1 C -S -1/T42* 2 -S -C T43* 3 -C S -1/T44* ----------------------------------------------------------45*46* Special cases:47* Let trig be any of sin, cos, or tan.48* trig(+-INF) is NaN, with signals;49* trig(NaN) is that NaN;50*51* Accuracy:52* TRIG(x) returns trig(x) nearly rounded53*/5455#include "fdlibm.h"5657#ifdef __STDC__58double tan(double x)59#else60double tan(x)61double x;62#endif63{64double y[2],z=0.0;65int n, ix;6667/* High word of x. */68ix = __HI(x);6970/* |x| ~< pi/4 */71ix &= 0x7fffffff;72if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);7374/* tan(Inf or NaN) is NaN */75else if (ix>=0x7ff00000) return x-x; /* NaN */7677/* argument reduction needed */78else {79n = __ieee754_rem_pio2(x,y);80return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even81-1 -- n odd */82}83}848586