assembly optimizations for fmod/remainder functions
[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 #include "__rem_pio2l.h"
13
14 void sincosl(long double x, long double *sin, long double *cos)
15 {
16         union IEEEl2bits u;
17         int n;
18         long double y[2], s, c;
19
20         u.e = x;
21         u.bits.sign = 0;
22
23         /* x = +-0 or subnormal */
24         if (!u.bits.exp) {
25                 *sin = x;
26                 *cos = 1.0;
27                 return;
28         }
29
30         /* x = nan or inf */
31         if (u.bits.exp == 0x7fff) {
32                 *sin = *cos = x - x;
33                 return;
34         }
35
36         /* |x| < pi/4 */
37         if (u.e < M_PI_4) {
38                 *sin = __sinl(x, 0, 0);
39                 *cos = __cosl(x, 0);
40                 return;
41         }
42
43         n = __rem_pio2l(x, y);
44         s = __sinl(y[0], y[1], 1);
45         c = __cosl(y[0], y[1]);
46         switch (n & 3) {
47         case 0:
48                 *sin = s;
49                 *cos = c;
50                 break;
51         case 1:
52                 *sin = c;
53                 *cos = -s;
54                 break;
55         case 2:
56                 *sin = -s;
57                 *cos = -c;
58                 break;
59         case 3:
60         default:
61                 *sin = -c;
62                 *cos = s;
63                 break;
64         }
65 }
66 #endif