]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - math/s_cexpf.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / math / s_cexpf.c
index 364be8ac3195e5c1e8226f05dfbc6d3fd2699804..001fec2492758f69e9ac675e25390850432dfcfb 100644 (file)
@@ -1,5 +1,5 @@
 /* Return value of complex exponential function for float complex value.
-   Copyright (C) 1997-2013 Free Software Foundation, Inc.
+   Copyright (C) 1997-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 
@@ -30,16 +30,16 @@ __cexpf (__complex__ float x)
   int rcls = fpclassify (__real__ x);
   int icls = fpclassify (__imag__ x);
 
-  if (__builtin_expect (rcls >= FP_ZERO, 1))
+  if (__glibc_likely (rcls >= FP_ZERO))
     {
       /* Real part is finite.  */
-      if (__builtin_expect (icls >= FP_ZERO, 1))
+      if (__glibc_likely (icls >= FP_ZERO))
        {
          /* Imaginary part is finite.  */
          const int t = (int) ((FLT_MAX_EXP - 1) * M_LN2);
          float sinix, cosix;
 
-         if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+         if (__glibc_likely (fabsf (__imag__ x) > FLT_MIN))
            {
              __sincosf (__imag__ x, &sinix, &cosix);
            }
@@ -74,6 +74,7 @@ __cexpf (__complex__ float x)
              __real__ retval = exp_val * cosix;
              __imag__ retval = exp_val * sinix;
            }
+         math_check_force_underflow_complex (retval);
        }
       else
        {
@@ -85,10 +86,10 @@ __cexpf (__complex__ float x)
          feraiseexcept (FE_INVALID);
        }
     }
-  else if (__builtin_expect (rcls == FP_INFINITE, 1))
+  else if (__glibc_likely (rcls == FP_INFINITE))
     {
       /* Real part is infinite.  */
-      if (__builtin_expect (icls >= FP_ZERO, 1))
+      if (__glibc_likely (icls >= FP_ZERO))
        {
          /* Imaginary part is finite.  */
          float value = signbit (__real__ x) ? 0.0 : HUGE_VALF;
@@ -103,7 +104,7 @@ __cexpf (__complex__ float x)
            {
              float sinix, cosix;
 
-             if (__builtin_expect (icls != FP_SUBNORMAL, 1))
+             if (__glibc_likely (fabsf (__imag__ x) > FLT_MIN))
                {
                  __sincosf (__imag__ x, &sinix, &cosix);
                }
@@ -133,12 +134,18 @@ __cexpf (__complex__ float x)
     }
   else
     {
-      /* If the real part is NaN the result is NaN + iNaN.  */
+      /* If the real part is NaN the result is NaN + iNaN unless the
+        imaginary part is zero.  */
       __real__ retval = __nanf ("");
-      __imag__ retval = __nanf ("");
+      if (icls == FP_ZERO)
+       __imag__ retval = __imag__ x;
+      else
+       {
+         __imag__ retval = __nanf ("");
 
-      if (rcls != FP_NAN || icls != FP_NAN)
-       feraiseexcept (FE_INVALID);
+         if (rcls != FP_NAN || icls != FP_NAN)
+           feraiseexcept (FE_INVALID);
+       }
     }
 
   return retval;