| OLD | NEW |
| 1 #include "libm.h" | 1 #include "libm.h" |
| 2 | 2 |
| 3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | 3 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 |
| 4 long double coshl(long double x) | 4 long double coshl(long double x) { |
| 5 { | 5 return cosh(x); |
| 6 » return cosh(x); | |
| 7 } | 6 } |
| 8 #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | 7 #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 |
| 9 long double coshl(long double x) | 8 long double coshl(long double x) { |
| 10 { | 9 union ldshape u = {x}; |
| 11 » union ldshape u = {x}; | 10 unsigned ex = u.i.se & 0x7fff; |
| 12 » unsigned ex = u.i.se & 0x7fff; | 11 uint32_t w; |
| 13 » uint32_t w; | 12 long double t; |
| 14 » long double t; | |
| 15 | 13 |
| 16 » /* |x| */ | 14 /* |x| */ |
| 17 » u.i.se = ex; | 15 u.i.se = ex; |
| 18 » x = u.f; | 16 x = u.f; |
| 19 » w = u.i.m >> 32; | 17 w = u.i.m >> 32; |
| 20 | 18 |
| 21 » /* |x| < log(2) */ | 19 /* |x| < log(2) */ |
| 22 » if (ex < 0x3fff-1 || (ex == 0x3fff-1 && w < 0xb17217f7)) { | 20 if (ex < 0x3fff - 1 || (ex == 0x3fff - 1 && w < 0xb17217f7)) { |
| 23 » » if (ex < 0x3fff-32) { | 21 if (ex < 0x3fff - 32) { |
| 24 » » » FORCE_EVAL(x + 0x1p120f); | 22 FORCE_EVAL(x + 0x1p120f); |
| 25 » » » return 1; | 23 return 1; |
| 26 » » } | 24 } |
| 27 » » t = expm1l(x); | 25 t = expm1l(x); |
| 28 » » return 1 + t*t/(2*(1+t)); | 26 return 1 + t * t / (2 * (1 + t)); |
| 29 » } | 27 } |
| 30 | 28 |
| 31 » /* |x| < log(LDBL_MAX) */ | 29 /* |x| < log(LDBL_MAX) */ |
| 32 » if (ex < 0x3fff+13 || (ex == 0x3fff+13 && w < 0xb17217f7)) { | 30 if (ex < 0x3fff + 13 || (ex == 0x3fff + 13 && w < 0xb17217f7)) { |
| 33 » » t = expl(x); | 31 t = expl(x); |
| 34 » » return 0.5*(t + 1/t); | 32 return 0.5 * (t + 1 / t); |
| 35 » } | 33 } |
| 36 | 34 |
| 37 » /* |x| > log(LDBL_MAX) or nan */ | 35 /* |x| > log(LDBL_MAX) or nan */ |
| 38 » t = expl(0.5*x); | 36 t = expl(0.5 * x); |
| 39 » return 0.5*t*t; | 37 return 0.5 * t * t; |
| 40 } | 38 } |
| 41 #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | 39 #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 |
| 42 // TODO: broken implementation to make things compile | 40 // TODO: broken implementation to make things compile |
| 43 long double coshl(long double x) | 41 long double coshl(long double x) { |
| 44 { | 42 return cosh(x); |
| 45 » return cosh(x); | |
| 46 } | 43 } |
| 47 #endif | 44 #endif |
| OLD | NEW |