s_tan.c revision 97409
1219019Sgabor/* @(#)s_tan.c 5.1 93/09/24 */ 2219019Sgabor/* 3219019Sgabor * ==================================================== 4219019Sgabor * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5219019Sgabor * 6219019Sgabor * Developed at SunPro, a Sun Microsystems, Inc. business. 7219019Sgabor * Permission to use, copy, modify, and distribute this 8219019Sgabor * software is freely granted, provided that this notice 9219019Sgabor * is preserved. 10219019Sgabor * ==================================================== 11219019Sgabor */ 12219019Sgabor 13219019Sgabor#ifndef lint 14219019Sgaborstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/s_tan.c 97409 2002-05-28 17:51:46Z alfred $"; 15219019Sgabor#endif 16219019Sgabor 17219019Sgabor/* tan(x) 18219019Sgabor * Return tangent function of x. 19219019Sgabor * 20219019Sgabor * kernel function: 21219019Sgabor * __kernel_tan ... tangent function on [-pi/4,pi/4] 22219019Sgabor * __ieee754_rem_pio2 ... argument reduction routine 23219019Sgabor * 24219019Sgabor * Method. 25219019Sgabor * Let S,C and T denote the sin, cos and tan respectively on 26219019Sgabor * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 27219019Sgabor * in [-pi/4 , +pi/4], and let n = k mod 4. 28219019Sgabor * We have 29219019Sgabor * 30219019Sgabor * n sin(x) cos(x) tan(x) 31219019Sgabor * ---------------------------------------------------------- 32219019Sgabor * 0 S C T 33219019Sgabor * 1 C -S -1/T 34219019Sgabor * 2 -S -C T 35219019Sgabor * 3 -C S -1/T 36219019Sgabor * ---------------------------------------------------------- 37219019Sgabor * 38219019Sgabor * Special cases: 39219019Sgabor * Let trig be any of sin, cos, or tan. 40219019Sgabor * trig(+-INF) is NaN, with signals; 41219019Sgabor * trig(NaN) is that NaN; 42219019Sgabor * 43219019Sgabor * Accuracy: 44219019Sgabor * TRIG(x) returns trig(x) nearly rounded 45219019Sgabor */ 46219019Sgabor 47219019Sgabor#include "math.h" 48219019Sgabor#include "math_private.h" 49219019Sgabor 50219019Sgabor double __generic_tan(double x) 51219019Sgabor{ 52219019Sgabor double y[2],z=0.0; 53219019Sgabor int32_t n, ix; 54219019Sgabor 55219019Sgabor /* High word of x. */ 56219019Sgabor GET_HIGH_WORD(ix,x); 57219019Sgabor 58219019Sgabor /* |x| ~< pi/4 */ 59219019Sgabor ix &= 0x7fffffff; 60219019Sgabor if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1); 61219019Sgabor 62219019Sgabor /* tan(Inf or NaN) is NaN */ 63219019Sgabor else if (ix>=0x7ff00000) return x-x; /* NaN */ 64219019Sgabor 65219019Sgabor /* argument reduction needed */ 66219019Sgabor else { 67219019Sgabor n = __ieee754_rem_pio2(x,y); 68219019Sgabor return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even 69219019Sgabor -1 -- n odd */ 70219019Sgabor } 71219019Sgabor} 72219019Sgabor