math: fix modfl.c bug
[musl] / src / math / sincosl.c
1 #include "libm.h"
2
3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
4 void sincosl(long double x, long double *sin, long double *cos)
5 {
6         double s, c;
7         sincos(x, &s, &c);
8         *sin = s;
9         *cos = c;
10 }
11 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
12 void sincosl(long double x, long double *sin, long double *cos)
13 {
14         union IEEEl2bits u;
15         int n;
16         long double y[2], s, c;
17
18         u.e = x;
19         u.bits.sign = 0;
20
21         /* x = +-0 or subnormal */
22         if (!u.bits.exp) {
23                 *sin = x;
24                 *cos = 1.0;
25                 return;
26         }
27
28         /* x = nan or inf */
29         if (u.bits.exp == 0x7fff) {
30                 *sin = *cos = x - x;
31                 return;
32         }
33
34         /* |x| < pi/4 */
35         if (u.e < M_PI_4) {
36                 *sin = __sinl(x, 0, 0);
37                 *cos = __cosl(x, 0);
38                 return;
39         }
40
41         n = __rem_pio2l(x, y);
42         s = __sinl(y[0], y[1], 1);
43         c = __cosl(y[0], y[1]);
44         switch (n & 3) {
45         case 0:
46                 *sin = s;
47                 *cos = c;
48                 break;
49         case 1:
50                 *sin = c;
51                 *cos = -s;
52                 break;
53         case 2:
54                 *sin = -s;
55                 *cos = -c;
56                 break;
57         case 3:
58         default:
59                 *sin = -c;
60                 *cos = s;
61                 break;
62         }
63 }
64 #endif