base/math/s_tan.c

Go to the documentation of this file.
00001 /* @(#)s_tan.c 5.1 93/09/24 */
00002 /*
00003  * ====================================================
00004  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00005  *
00006  * Developed at SunPro, a Sun Microsystems, Inc. business.
00007  * Permission to use, copy, modify, and distribute this
00008  * software is freely granted, provided that this notice 
00009  * is preserved.
00010  * ====================================================
00011  */
00012 
00013 #if defined(LIBM_SCCS) && !defined(lint)
00014 static char rcsid[] = "$NetBSD: s_tan.c,v 1.7 1995/05/10 20:48:18 jtc Exp $";
00015 #endif
00016 
00017 /* tan(x)
00018  * Return tangent function of x.
00019  *
00020  * kernel function:
00021  *  __kernel_tan        ... tangent function on [-pi/4,pi/4]
00022  *  __ieee754_rem_pio2  ... argument reduction routine
00023  *
00024  * Method.
00025  *      Let S,C and T denote the sin, cos and tan respectively on 
00026  *  [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 
00027  *  in [-pi/4 , +pi/4], and let n = k mod 4.
00028  *  We have
00029  *
00030  *          n        sin(x)      cos(x)        tan(x)
00031  *     ----------------------------------------------------------
00032  *      0          S       C         T
00033  *      1          C      -S        -1/T
00034  *      2         -S      -C         T
00035  *      3         -C       S        -1/T
00036  *     ----------------------------------------------------------
00037  *
00038  * Special cases:
00039  *      Let trig be any of sin, cos, or tan.
00040  *      trig(+-INF)  is NaN, with signals;
00041  *      trig(NaN)    is that NaN;
00042  *
00043  * Accuracy:
00044  *  TRIG(x) returns trig(x) nearly rounded 
00045  */
00046 
00047 #include "math.h"
00048 #include "mathP.h"
00049 
00050 #ifdef __STDC__
00051     double tan(double x)
00052 #else
00053     double tan(x)
00054     double x;
00055 #endif
00056 {
00057     double y[2],z=0.0;
00058     int32_t n, ix;
00059 
00060     /* High word of x. */
00061     GET_HIGH_WORD(ix,x);
00062 
00063     /* |x| ~< pi/4 */
00064     ix &= 0x7fffffff;
00065     if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
00066 
00067     /* tan(Inf or NaN) is NaN */
00068     else if (ix>=0x7ff00000) return x-x;        /* NaN */
00069 
00070     /* argument reduction needed */
00071     else {
00072         n = __ieee754_rem_pio2(x,y);
00073         return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /*   1 -- n even
00074                             -1 -- n odd */
00075     }
00076 }

Generated on Tue Feb 2 17:46:05 2010 for RTAI API by  doxygen 1.4.7