s_tan.c revision 2116
12116Sjkh/* @(#)s_tan.c 5.1 93/09/24 */ 22116Sjkh/* 32116Sjkh * ==================================================== 42116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 52116Sjkh * 62116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business. 72116Sjkh * Permission to use, copy, modify, and distribute this 82116Sjkh * software is freely granted, provided that this notice 92116Sjkh * is preserved. 102116Sjkh * ==================================================== 112116Sjkh */ 122116Sjkh 132116Sjkh#ifndef lint 142116Sjkhstatic char rcsid[] = "$Id: s_tan.c,v 1.5 1994/08/18 23:10:19 jtc Exp $"; 152116Sjkh#endif 162116Sjkh 172116Sjkh/* tan(x) 182116Sjkh * Return tangent function of x. 192116Sjkh * 202116Sjkh * kernel function: 212116Sjkh * __kernel_tan ... tangent function on [-pi/4,pi/4] 222116Sjkh * __ieee754_rem_pio2 ... argument reduction routine 232116Sjkh * 242116Sjkh * Method. 252116Sjkh * Let S,C and T denote the sin, cos and tan respectively on 262116Sjkh * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 272116Sjkh * in [-pi/4 , +pi/4], and let n = k mod 4. 282116Sjkh * We have 292116Sjkh * 302116Sjkh * n sin(x) cos(x) tan(x) 312116Sjkh * ---------------------------------------------------------- 322116Sjkh * 0 S C T 332116Sjkh * 1 C -S -1/T 342116Sjkh * 2 -S -C T 352116Sjkh * 3 -C S -1/T 362116Sjkh * ---------------------------------------------------------- 372116Sjkh * 382116Sjkh * Special cases: 392116Sjkh * Let trig be any of sin, cos, or tan. 402116Sjkh * trig(+-INF) is NaN, with signals; 412116Sjkh * trig(NaN) is that NaN; 422116Sjkh * 432116Sjkh * Accuracy: 442116Sjkh * TRIG(x) returns trig(x) nearly rounded 452116Sjkh */ 462116Sjkh 472116Sjkh#include "math.h" 482116Sjkh#include "math_private.h" 492116Sjkh 502116Sjkh#ifdef __STDC__ 512116Sjkh double tan(double x) 522116Sjkh#else 532116Sjkh double tan(x) 542116Sjkh double x; 552116Sjkh#endif 562116Sjkh{ 572116Sjkh double y[2],z=0.0; 582116Sjkh int32_t n, ix; 592116Sjkh 602116Sjkh /* High word of x. */ 612116Sjkh GET_HIGH_WORD(ix,x); 622116Sjkh 632116Sjkh /* |x| ~< pi/4 */ 642116Sjkh ix &= 0x7fffffff; 652116Sjkh if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1); 662116Sjkh 672116Sjkh /* tan(Inf or NaN) is NaN */ 682116Sjkh else if (ix>=0x7ff00000) return x-x; /* NaN */ 692116Sjkh 702116Sjkh /* argument reduction needed */ 712116Sjkh else { 722116Sjkh n = __ieee754_rem_pio2(x,y); 732116Sjkh return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even 742116Sjkh -1 -- n odd */ 752116Sjkh } 762116Sjkh} 77