diff options
author | Joseph Myers <joseph@codesourcery.com> | 2012-05-19 15:35:29 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2012-05-19 15:35:29 +0000 |
commit | e0b16cc25c4bae1ac45ec6ce90341f9a7d1ae6b6 (patch) | |
tree | 82c8f2f5c13fba98b2b028475bf84d9cd15bd6b8 /math/s_csinh.c | |
parent | f66f0ce833523a47e12b4a3eacab6b20866ab033 (diff) | |
download | glibc-e0b16cc25c4bae1ac45ec6ce90341f9a7d1ae6b6.zip glibc-e0b16cc25c4bae1ac45ec6ce90341f9a7d1ae6b6.tar.gz glibc-e0b16cc25c4bae1ac45ec6ce90341f9a7d1ae6b6.tar.bz2 |
Fix ccos, csin, ccosh, csinh overflows (bug 14123).
Diffstat (limited to 'math/s_csinh.c')
-rw-r--r-- | math/s_csinh.c | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/math/s_csinh.c b/math/s_csinh.c index f054dfc..56bb256 100644 --- a/math/s_csinh.c +++ b/math/s_csinh.c @@ -1,5 +1,5 @@ /* Complex sine hyperbole function for double. - Copyright (C) 1997, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -20,9 +20,8 @@ #include <complex.h> #include <fenv.h> #include <math.h> - #include <math_private.h> - +#include <float.h> __complex__ double __csinh (__complex__ double x) @@ -40,14 +39,44 @@ __csinh (__complex__ double x) if (__builtin_expect (icls >= FP_ZERO, 1)) { /* Imaginary part is finite. */ - double sinh_val = __ieee754_sinh (__real__ x); - double cosh_val = __ieee754_cosh (__real__ x); + const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2); double sinix, cosix; __sincos (__imag__ x, &sinix, &cosix); - __real__ retval = sinh_val * cosix; - __imag__ retval = cosh_val * sinix; + if (fabs (__real__ x) > t) + { + double exp_t = __ieee754_exp (t); + double rx = fabs (__real__ x); + if (signbit (__real__ x)) + cosix = -cosix; + rx -= t; + sinix *= exp_t / 2.0; + cosix *= exp_t / 2.0; + if (rx > t) + { + rx -= t; + sinix *= exp_t; + cosix *= exp_t; + } + if (rx > t) + { + /* Overflow (original real part of x > 3t). */ + __real__ retval = DBL_MAX * cosix; + __imag__ retval = DBL_MAX * sinix; + } + else + { + double exp_val = __ieee754_exp (rx); + __real__ retval = exp_val * cosix; + __imag__ retval = exp_val * sinix; + } + } + else + { + __real__ retval = __ieee754_sinh (__real__ x) * cosix; + __imag__ retval = __ieee754_cosh (__real__ x) * sinix; + } if (negate) __real__ retval = -__real__ retval; |