]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Math/s_tan.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / StdLib / LibC / Math / s_tan.c
CommitLineData
2aa62f2b 1/* @(#)s_tan.c 5.1 93/09/24 */\r
2/*\r
3 * ====================================================\r
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
5 *\r
6 * Developed at SunPro, a Sun Microsystems, Inc. business.\r
7 * Permission to use, copy, modify, and distribute this\r
8 * software is freely granted, provided that this notice\r
9 * is preserved.\r
10 * ====================================================\r
11 */\r
12#include <LibConfig.h>\r
13#include <sys/EfiCdefs.h>\r
14#if defined(LIBM_SCCS) && !defined(lint)\r
15__RCSID("$NetBSD: s_tan.c,v 1.10 2002/05/26 22:01:58 wiz Exp $");\r
16#endif\r
17\r
18/* tan(x)\r
19 * Return tangent function of x.\r
20 *\r
21 * kernel function:\r
22 * __kernel_tan ... tangent function on [-pi/4,pi/4]\r
23 * __ieee754_rem_pio2 ... argument reduction routine\r
24 *\r
25 * Method.\r
26 * Let S,C and T denote the sin, cos and tan respectively on\r
27 * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2\r
28 * in [-pi/4 , +pi/4], and let n = k mod 4.\r
29 * We have\r
30 *\r
31 * n sin(x) cos(x) tan(x)\r
32 * ----------------------------------------------------------\r
33 * 0 S C T\r
34 * 1 C -S -1/T\r
35 * 2 -S -C T\r
36 * 3 -C S -1/T\r
37 * ----------------------------------------------------------\r
38 *\r
39 * Special cases:\r
40 * Let trig be any of sin, cos, or tan.\r
41 * trig(+-INF) is NaN, with signals;\r
42 * trig(NaN) is that NaN;\r
43 *\r
44 * Accuracy:\r
45 * TRIG(x) returns trig(x) nearly rounded\r
46 */\r
47\r
48#include "math.h"\r
49#include "math_private.h"\r
50\r
51double\r
52tan(double x)\r
53{\r
54 double y[2],z=0.0;\r
55 int32_t n, ix;\r
56\r
57 /* High word of x. */\r
58 GET_HIGH_WORD(ix,x);\r
59\r
60 /* |x| ~< pi/4 */\r
61 ix &= 0x7fffffff;\r
62 if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);\r
63\r
64 /* tan(Inf or NaN) is NaN */\r
65 else if (ix>=0x7ff00000) return x-x; /* NaN */\r
66\r
67 /* argument reduction needed */\r
68 else {\r
69 n = __ieee754_rem_pio2(x,y);\r
70 return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even\r
71 -1 -- n odd */\r
72 }\r
73}\r