1 /*-
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
5 * Developed at SunSoft, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
10 *
11 * k_sin.c and k_cos.c merged by Steven G. Kargl.
12 */
13
14 #include <sys/cdefs.h>
15 __FBSDID("$FreeBSD: head/lib/msun/src/k_sincos.h 319047 2017-05-28 06:13:38Z mmel $");
16
17 static const double
18 S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
19 S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
20 S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
21 S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
22 S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
23 S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
24
25 static const double
26 C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
27 C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
28 C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
29 C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
30 C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
31 C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
32
33 static inline void
__kernel_sincos(double x,double y,int iy,double * sn,double * cs)34 __kernel_sincos(double x, double y, int iy, double *sn, double *cs)
35 {
36 double hz, r, v, w, z;
37
38 z = x * x;
39 w = z * z;
40 r = S2 + z * (S3 + z * S4) + z * w * (S5 + z * S6);
41 v = z * x;
42
43 if (iy == 0)
44 *sn = x + v * (S1 + z * r);
45 else
46 *sn = x - ((z * (y / 2 - v * r) - y) - v * S1);
47
48 r = z * (C1 + z * (C2 + z * C3)) + w * w * (C4 + z * (C5 + z * C6));
49 hz = z / 2;
50 w = 1 - hz;
51 *cs = w + (((1 - w) - hz) + (z * r - x * y));
52 }
53