]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Math/s_sin.c
ArmPkg: ArmLib: purge incorrect ArmDrainWriteBuffer () alias
[mirror_edk2.git] / StdLib / LibC / Math / s_sin.c
CommitLineData
2aa62f2b 1/* @(#)s_sin.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_sin.c,v 1.10 2002/05/26 22:01:58 wiz Exp $");\r
16#endif\r
17\r
18/* sin(x)\r
19 * Return sine function of x.\r
20 *\r
21 * kernel function:\r
22 * __kernel_sin ... sine function on [-pi/4,pi/4]\r
23 * __kernel_cos ... cose function on [-pi/4,pi/4]\r
24 * __ieee754_rem_pio2 ... argument reduction routine\r
25 *\r
26 * Method.\r
27 * Let S,C and T denote the sin, cos and tan respectively on\r
28 * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2\r
29 * in [-pi/4 , +pi/4], and let n = k mod 4.\r
30 * We have\r
31 *\r
32 * n sin(x) cos(x) tan(x)\r
33 * ----------------------------------------------------------\r
34 * 0 S C T\r
35 * 1 C -S -1/T\r
36 * 2 -S -C T\r
37 * 3 -C S -1/T\r
38 * ----------------------------------------------------------\r
39 *\r
40 * Special cases:\r
41 * Let trig be any of sin, cos, or tan.\r
42 * trig(+-INF) is NaN, with signals;\r
43 * trig(NaN) is that NaN;\r
44 *\r
45 * Accuracy:\r
46 * TRIG(x) returns trig(x) nearly rounded\r
47 */\r
48\r
49#include "math.h"\r
50#include "math_private.h"\r
51\r
52double\r
53sin(double x)\r
54{\r
55 double y[2],z=0.0;\r
56 int32_t n, ix;\r
57\r
58 /* High word of x. */\r
59 GET_HIGH_WORD(ix,x);\r
60\r
61 /* |x| ~< pi/4 */\r
62 ix &= 0x7fffffff;\r
63 if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);\r
64\r
65 /* sin(Inf or NaN) is NaN */\r
66 else if (ix>=0x7ff00000) return x-x;\r
67\r
68 /* argument reduction needed */\r
69 else {\r
70 n = __ieee754_rem_pio2(x,y);\r
71 switch(n&3) {\r
72 case 0: return __kernel_sin(y[0],y[1],1);\r
73 case 1: return __kernel_cos(y[0],y[1]);\r
74 case 2: return -__kernel_sin(y[0],y[1],1);\r
75 default:\r
76 return -__kernel_cos(y[0],y[1]);\r
77 }\r
78 }\r
79}\r