summary refs log tree commit diff
path: root/math/s_csinl.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2012-05-19 15:35:29 +0000
committerJoseph Myers <joseph@codesourcery.com>2012-05-19 15:35:29 +0000
commite0b16cc25c4bae1ac45ec6ce90341f9a7d1ae6b6 (patch)
tree82c8f2f5c13fba98b2b028475bf84d9cd15bd6b8 /math/s_csinl.c
parentf66f0ce833523a47e12b4a3eacab6b20866ab033 (diff)
downloadglibc-e0b16cc25c4bae1ac45ec6ce90341f9a7d1ae6b6.tar.gz
glibc-e0b16cc25c4bae1ac45ec6ce90341f9a7d1ae6b6.tar.xz
glibc-e0b16cc25c4bae1ac45ec6ce90341f9a7d1ae6b6.zip
Fix ccos, csin, ccosh, csinh overflows (bug 14123).
Diffstat (limited to 'math/s_csinl.c')
-rw-r--r--math/s_csinl.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/math/s_csinl.c b/math/s_csinl.c
index df20e8b338..ff43256e54 100644
--- a/math/s_csinl.c
+++ b/math/s_csinl.c
@@ -1,5 +1,5 @@
 /* Complex sine function for long 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__ long double
 __csinl (__complex__ long double x)
@@ -40,14 +39,44 @@ __csinl (__complex__ long double x)
       if (__builtin_expect (rcls >= FP_ZERO, 1))
 	{
 	  /* Real part is finite.  */
-	  long double sinh_val = __ieee754_sinhl (__imag__ x);
-	  long double cosh_val = __ieee754_coshl (__imag__ x);
+	  const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l);
 	  long double sinix, cosix;
 
 	  __sincosl (__real__ x, &sinix, &cosix);
 
-	  __real__ retval = cosh_val * sinix;
-	  __imag__ retval = sinh_val * cosix;
+	  if (fabsl (__imag__ x) > t)
+	    {
+	      long double exp_t = __ieee754_expl (t);
+	      long double ix = fabsl (__imag__ x);
+	      if (signbit (__imag__ x))
+		cosix = -cosix;
+	      ix -= t;
+	      sinix *= exp_t / 2.0L;
+	      cosix *= exp_t / 2.0L;
+	      if (ix > t)
+		{
+		  ix -= t;
+		  sinix *= exp_t;
+		  cosix *= exp_t;
+		}
+	      if (ix > t)
+		{
+		  /* Overflow (original imaginary part of x > 3t).  */
+		  __real__ retval = LDBL_MAX * sinix;
+		  __imag__ retval = LDBL_MAX * cosix;
+		}
+	      else
+		{
+		  long double exp_val = __ieee754_expl (ix);
+		  __real__ retval = exp_val * sinix;
+		  __imag__ retval = exp_val * cosix;
+		}
+	    }
+	  else
+	    {
+	      __real__ retval = __ieee754_coshl (__imag__ x) * sinix;
+	      __imag__ retval = __ieee754_sinhl (__imag__ x) * cosix;
+	    }
 
 	  if (negate)
 	    __real__ retval = -__real__ retval;