POK
|
00001 /* 00002 * POK header 00003 * 00004 * The following file is a part of the POK project. Any modification should 00005 * made according to the POK licence. You CANNOT use this file or a part of 00006 * this file is this part of a file for your own project 00007 * 00008 * For more information on the POK licence, please see our LICENCE FILE 00009 * 00010 * Please follow the coding guidelines described in doc/CODING_GUIDELINES 00011 * 00012 * Copyright (c) 2007-2009 POK team 00013 * 00014 * Created by julien on Fri Jan 30 14:41:34 2009 00015 */ 00016 00017 /* @(#)s_tan.c 5.1 93/09/24 */ 00018 /* 00019 * ==================================================== 00020 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 00021 * 00022 * Developed at SunPro, a Sun Microsystems, Inc. business. 00023 * Permission to use, copy, modify, and distribute this 00024 * software is freely granted, provided that this notice 00025 * is preserved. 00026 * ==================================================== 00027 */ 00028 00029 #ifdef POK_NEEDS_LIBMATH 00030 00031 /* tan(x) 00032 * Return tangent function of x. 00033 * 00034 * kernel function: 00035 * __kernel_tan ... tangent function on [-pi/4,pi/4] 00036 * __ieee754_rem_pio2 ... argument reduction routine 00037 * 00038 * Method. 00039 * Let S,C and T denote the sin, cos and tan respectively on 00040 * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 00041 * in [-pi/4 , +pi/4], and let n = k mod 4. 00042 * We have 00043 * 00044 * n sin(x) cos(x) tan(x) 00045 * ---------------------------------------------------------- 00046 * 0 S C T 00047 * 1 C -S -1/T 00048 * 2 -S -C T 00049 * 3 -C S -1/T 00050 * ---------------------------------------------------------- 00051 * 00052 * Special cases: 00053 * Let trig be any of sin, cos, or tan. 00054 * trig(+-INF) is NaN, with signals; 00055 * trig(NaN) is that NaN; 00056 * 00057 * Accuracy: 00058 * TRIG(x) returns trig(x) nearly rounded 00059 */ 00060 00061 #include <libm.h> 00062 #include "math_private.h" 00063 00064 double 00065 tan(double x) 00066 { 00067 double y[2],z=0.0; 00068 int32_t n, ix; 00069 00070 /* High word of x. */ 00071 GET_HIGH_WORD(ix,x); 00072 00073 /* |x| ~< pi/4 */ 00074 ix &= 0x7fffffff; 00075 if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1); 00076 00077 /* tan(Inf or NaN) is NaN */ 00078 else if (ix>=0x7ff00000) return x-x; /* NaN */ 00079 00080 /* argument reduction needed */ 00081 else { 00082 n = __ieee754_rem_pio2(x,y); 00083 return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even 00084 -1 -- n odd */ 00085 } 00086 } 00087 00088 #endif