diff options
Diffstat (limited to 'sysdeps/libm-ieee754/s_ccosh.c')
-rw-r--r-- | sysdeps/libm-ieee754/s_ccosh.c | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/sysdeps/libm-ieee754/s_ccosh.c b/sysdeps/libm-ieee754/s_ccosh.c index f01b245e77..b9d7b82f5e 100644 --- a/sysdeps/libm-ieee754/s_ccosh.c +++ b/sysdeps/libm-ieee754/s_ccosh.c @@ -21,47 +21,47 @@ #include <complex.h> #include <math.h> +#include "math_private.h" + __complex__ double __ccosh (__complex__ double x) { __complex__ double retval; + int rcls = fpclassify (__real__ x); + int icls = fpclassify (__imag__ x); __real__ x = fabs (__real__ x); - if (isfinite (__real__ x)) + if (rcls >= FP_ZERO) { - if (isfinite (__imag__ x)) + /* Real part is finite. */ + if (icls >= FP_ZERO) { - double exp_val = __exp (__real__ x); - double rec_exp_val = 1.0 / exp_val; + /* Imaginary part is finite. */ + double cosh_val = __ieee754_cosh (__real__ x); - __real__ retval = 0.5 * (exp_val + rec_exp_val) * __cos (__imag__ x); - __imag__ retval = 0.5 * (exp_val + rec_exp_val) * __sin (__imag__ x); + __real__ retval = cosh_val * __cos (__imag__ x); + __imag__ retval = cosh_val * __sin (__imag__ x); } else { - if (__real__ x == 0) - { - __imag__ retval = 0.0; - __real__ retval = __nan ("") + __nan (""); - } - else - { - __real__ retval = __nan (""); - __imag__ retval = __nan ("") + __nan (""); - } + __imag__ retval = __real__ x == 0.0 ? 0.0 : __nan (""); + __real__ retval = __nan ("") + __nan (""); } } - else if (__isinf (__real__ x)) + else if (rcls == FP_INFINITE) { - if (__imag__ x == 0.0) + /* Real part is infinite. */ + if (icls == FP_ZERO) { + /* Imaginary part is 0.0. */ __real__ retval = HUGE_VAL; __imag__ retval = __imag__ x; } - else if (isfinite (__imag__ x)) + else if (icls > FP_ZERO) { + /* Imaginary part is finite. */ __real__ retval = __copysign (HUGE_VAL, __cos (__imag__ x)); __imag__ retval = __copysign (HUGE_VAL, __sin (__imag__ x)); } @@ -74,16 +74,8 @@ __ccosh (__complex__ double x) } else { - if (__imag__ x == 0.0) - { - __real__ retval = __nan (""); - __imag__ retval = __imag__ x; - } - else - { - __real__ retval = __nan (""); - __imag__ retval = __nan (""); - } + __real__ retval = __nan (""); + __imag__ retval = __imag__ x == 0.0 ? __imag__ x : __nan (""); } return retval; |