|
22 | 22 |
|
23 | 23 | #include <math.h> |
24 | 24 |
|
25 | | -#define p0 -0.630767364049772e+6 |
26 | | -#define p1 -0.899127202203951e+5 |
27 | | -#define p2 -0.289421135598956e+4 |
28 | | -#define p3 -0.263056321339750e+2 |
29 | | -#define q0 -0.630767364049772e+6 |
30 | | -#define q1 0.152151737879002e+5 |
31 | | -#define q2 -0.173678953558234e+3 |
32 | | - |
| 25 | +#define p0 -0.630767364049772e+6f |
| 26 | +#define p1 -0.899127202203951e+5f |
| 27 | +#define p2 -0.289421135598956e+4f |
| 28 | +#define p3 -0.263056321339750e+2f |
| 29 | +#define q0 -0.630767364049772e+6f |
| 30 | +#define q1 0.152151737879002e+5f |
| 31 | +#define q2 -0.173678953558234e+3f |
| 32 | + |
| 33 | +/** |
| 34 | + * @remarks Minimum ulp: |
| 35 | + * ulp of -3 at +0x1.eec25ap-9 with ideal expf (|x| < 21.0f) |
| 36 | + * ulp of -18 at +0x1.0a049cp+4 with current expf (|x| < 21.0f) |
| 37 | + */ |
33 | 38 | float _sinhf_c(float arg) { |
34 | | - float temp, argsq; |
35 | | - register int sign; |
36 | | - |
37 | | - sign = 1; |
38 | | - if(arg < 0) { |
39 | | - arg = -arg; |
40 | | - sign = -1; |
41 | | - } |
42 | | - |
43 | | - if(arg > 21.) { |
44 | | - temp = expf(arg)/2; |
45 | | - if (sign>0) |
46 | | - return(temp); |
47 | | - else |
48 | | - return(-temp); |
| 39 | + float temp, argsq, x; |
| 40 | + x = fabsf(arg); |
| 41 | + |
| 42 | + if (x > 21.0f) { |
| 43 | + temp = expf(x) / 2.0f; |
| 44 | + } else if (x > 0.5f) { |
| 45 | + temp = (expf(x) - expf(-x)) / 2.0f; |
| 46 | + } else { |
| 47 | + argsq = x * x; |
| 48 | + temp = (((p3*argsq+p2)*argsq+p1)*argsq+p0) * x; |
| 49 | + temp /= (((argsq+q2)*argsq+q1)*argsq+q0); |
49 | 50 | } |
50 | | - |
51 | | - if(arg > 0.5) { |
52 | | - return(sign*(expf(arg) - expf(-arg))/2); |
53 | | - } |
54 | | - |
55 | | - argsq = arg*arg; |
56 | | - temp = (((p3*argsq+p2)*argsq+p1)*argsq+p0)*arg; |
57 | | - temp /= (((argsq+q2)*argsq+q1)*argsq+q0); |
58 | | - return(sign*temp); |
| 51 | + return copysignf(temp, arg); |
59 | 52 | } |
60 | 53 |
|
61 | 54 | double _sinh_c(double, double *) __attribute__((alias("_sinhf_c"))); |
0 commit comments