]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Clean up some complex functions raising FE_INVALID.
authorJoseph Myers <joseph@codesourcery.com>
Fri, 14 Oct 2016 00:12:56 +0000 (00:12 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Fri, 14 Oct 2016 00:12:56 +0000 (00:12 +0000)
Some of the complex arithmetic functions have the following pattern:
in some piece of code, one part of the input (real or imaginary,
depending on the function) is either infinite or NaN.  Part of the
result is to be set to NaN in either case, and FE_INVALID raised only
if the relevant part of the input was infinite.

In such a case, there is no actual need for the conditional on the
type of the input, since subtracting the relevant part of the input
from itself will produce a NaN, with FE_INVALID only if the relevant
part of the input was infinite.  This simplifies the code, and as a
quality-of-implementation matter also improves things by propagating
NaN payloads.  (Right now these functions always raise FE_INVALID for
signaling NaN arguments because of the call to fpclassify - at least
unless glibc is built with -Os - but if fpclassify moves to using
integer arithmetic in future, doing arithmetic on the NaN argument
also ensures an exception for sNaNs.)

Tested for x86_64 and x86.

* math/s_ccosh_template.c (M_DECL_FUNC (__ccosh)): Instead of
raising FE_INVALID with feraisexcept in case where part of
argument is infinite, subtract that part of argument from itself.
* math/s_cexp_template.c (M_DECL_FUNC (__cexp)): Likewise.
* math/s_csin_template.c (M_DECL_FUNC (__csin)): Likewise.
* math/s_csinh_template.c (M_DECL_FUNC (__csinh)): Likewise.

ChangeLog
math/s_ccosh_template.c
math/s_cexp_template.c
math/s_csin_template.c
math/s_csinh_template.c

index 5b8443bf84570d8c121211e1c657f3efa49dbea2..b3332bcb40520d60fffbbccd2940382bffc9c603 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2016-10-13  Joseph Myers  <joseph@codesourcery.com>
+
+       * math/s_ccosh_template.c (M_DECL_FUNC (__ccosh)): Instead of
+       raising FE_INVALID with feraisexcept in case where part of
+       argument is infinite, subtract that part of argument from itself.
+       * math/s_cexp_template.c (M_DECL_FUNC (__cexp)): Likewise.
+       * math/s_csin_template.c (M_DECL_FUNC (__csin)): Likewise.
+       * math/s_csinh_template.c (M_DECL_FUNC (__csinh)): Likewise.
+
 2016-10-12  Joseph Myers  <joseph@codesourcery.com>
 
        * math/libm-test.inc (totalorder_test_data): Add more tests.
index 7fea5c9f57cd82594e3c691eb53533a96b2e8cbd..524072439264fad650541afa38fa798ee81ec36a 100644 (file)
@@ -88,10 +88,7 @@ M_DECL_FUNC (__ccosh) (CFLOAT x)
       else
        {
          __imag__ retval = __real__ x == 0 ? 0 : M_NAN;
-         __real__ retval = M_NAN;
-
-         if (icls == FP_INFINITE)
-           feraiseexcept (FE_INVALID);
+         __real__ retval = __imag__ x - __imag__ x;
        }
     }
   else if (rcls == FP_INFINITE)
@@ -125,10 +122,7 @@ M_DECL_FUNC (__ccosh) (CFLOAT x)
       else
        {
          __real__ retval = M_HUGE_VAL;
-         __imag__ retval = M_NAN;
-
-         if (icls == FP_INFINITE)
-           feraiseexcept (FE_INVALID);
+         __imag__ retval = __imag__ x - __imag__ x;
        }
     }
   else
index a60afe0cac2d8eb250a999b8459b7d04528d366a..dd46d96a32a310a5c2fe7977206018b43317c629 100644 (file)
@@ -121,10 +121,7 @@ M_DECL_FUNC (__cexp) (CFLOAT x)
       else if (signbit (__real__ x) == 0)
        {
          __real__ retval = M_HUGE_VAL;
-         __imag__ retval = M_NAN;
-
-         if (icls == FP_INFINITE)
-           feraiseexcept (FE_INVALID);
+         __imag__ retval = __imag__ x - __imag__ x;
        }
       else
        {
index 59d887693ce24171747bad155fe470ed502b7ad7..2fe0b157cbc1c2d3cfcf5f1443898dca09ae8523 100644 (file)
@@ -96,11 +96,8 @@ M_DECL_FUNC (__csin) (CFLOAT x)
          if (icls == FP_ZERO)
            {
              /* Imaginary part is 0.0.  */
-             __real__ retval = M_NAN;
+             __real__ retval = __real__ x - __real__ x;
              __imag__ retval = __imag__ x;
-
-             if (rcls == FP_INFINITE)
-               feraiseexcept (FE_INVALID);
            }
          else
            {
@@ -145,12 +142,8 @@ M_DECL_FUNC (__csin) (CFLOAT x)
        }
       else
        {
-         /* The addition raises the invalid exception.  */
-         __real__ retval = M_NAN;
+         __real__ retval = __real__ x - __real__ x;
          __imag__ retval = M_HUGE_VAL;
-
-         if (rcls == FP_INFINITE)
-           feraiseexcept (FE_INVALID);
        }
     }
   else
index 45fbb36fd9feccd3a785377c2bbcca1d7082d16c..e5fd4d5857645f0c03b97d82b24eeb77accc1f46 100644 (file)
@@ -97,10 +97,7 @@ M_DECL_FUNC (__csinh) (CFLOAT x)
            {
              /* Real part is 0.0.  */
              __real__ retval = M_COPYSIGN (0, negate ? -1 : 1);
-             __imag__ retval = M_NAN;
-
-             if (icls == FP_INFINITE)
-               feraiseexcept (FE_INVALID);
+             __imag__ retval = __imag__ x - __imag__ x;
            }
          else
            {
@@ -144,10 +141,7 @@ M_DECL_FUNC (__csinh) (CFLOAT x)
       else
        {
          __real__ retval = M_HUGE_VAL;
-         __imag__ retval = M_NAN;
-
-         if (icls == FP_INFINITE)
-           feraiseexcept (FE_INVALID);
+         __imag__ retval = __imag__ x - __imag__ x;
        }
     }
   else