OLD | NEW |
1 #define _GNU_SOURCE | 1 #define _GNU_SOURCE |
2 #include "libm.h" | 2 #include "libm.h" |
3 | 3 |
4 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | 4 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 |
5 void sincosl(long double x, long double *sin, long double *cos) | 5 void sincosl(long double x, long double* sin, long double* cos) { |
6 { | 6 double sind, cosd; |
7 » double sind, cosd; | 7 sincos(x, &sind, &cosd); |
8 » sincos(x, &sind, &cosd); | 8 *sin = sind; |
9 » *sin = sind; | 9 *cos = cosd; |
10 » *cos = cosd; | |
11 } | 10 } |
12 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | 11 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 |
13 void sincosl(long double x, long double *sin, long double *cos) | 12 void sincosl(long double x, long double* sin, long double* cos) { |
14 { | 13 union ldshape u = {x}; |
15 » union ldshape u = {x}; | 14 unsigned n; |
16 » unsigned n; | 15 long double y[2], s, c; |
17 » long double y[2], s, c; | |
18 | 16 |
19 » u.i.se &= 0x7fff; | 17 u.i.se &= 0x7fff; |
20 » if (u.i.se == 0x7fff) { | 18 if (u.i.se == 0x7fff) { |
21 » » *sin = *cos = x - x; | 19 *sin = *cos = x - x; |
22 » » return; | 20 return; |
23 » } | 21 } |
24 » if (u.f < M_PI_4) { | 22 if (u.f < M_PI_4) { |
25 » » if (u.i.se < 0x3fff - LDBL_MANT_DIG) { | 23 if (u.i.se < 0x3fff - LDBL_MANT_DIG) { |
26 » » » /* raise underflow if subnormal */ | 24 /* raise underflow if subnormal */ |
27 » » » if (u.i.se == 0) FORCE_EVAL(x*0x1p-120f); | 25 if (u.i.se == 0) |
28 » » » *sin = x; | 26 FORCE_EVAL(x * 0x1p-120f); |
29 » » » /* raise inexact if x!=0 */ | 27 *sin = x; |
30 » » » *cos = 1.0 + x; | 28 /* raise inexact if x!=0 */ |
31 » » » return; | 29 *cos = 1.0 + x; |
32 » » } | 30 return; |
33 » » *sin = __sinl(x, 0, 0); | 31 } |
34 » » *cos = __cosl(x, 0); | 32 *sin = __sinl(x, 0, 0); |
35 » » return; | 33 *cos = __cosl(x, 0); |
36 » } | 34 return; |
37 » n = __rem_pio2l(x, y); | 35 } |
38 » s = __sinl(y[0], y[1], 1); | 36 n = __rem_pio2l(x, y); |
39 » c = __cosl(y[0], y[1]); | 37 s = __sinl(y[0], y[1], 1); |
40 » switch (n & 3) { | 38 c = __cosl(y[0], y[1]); |
41 » case 0: | 39 switch (n & 3) { |
42 » » *sin = s; | 40 case 0: |
43 » » *cos = c; | 41 *sin = s; |
44 » » break; | 42 *cos = c; |
45 » case 1: | 43 break; |
46 » » *sin = c; | 44 case 1: |
47 » » *cos = -s; | 45 *sin = c; |
48 » » break; | 46 *cos = -s; |
49 » case 2: | 47 break; |
50 » » *sin = -s; | 48 case 2: |
51 » » *cos = -c; | 49 *sin = -s; |
52 » » break; | 50 *cos = -c; |
53 » case 3: | 51 break; |
54 » default: | 52 case 3: |
55 » » *sin = -c; | 53 default: |
56 » » *cos = s; | 54 *sin = -c; |
57 » » break; | 55 *cos = s; |
58 » } | 56 break; |
| 57 } |
59 } | 58 } |
60 #endif | 59 #endif |
OLD | NEW |