about summary refs log tree commit diff
path: root/math/s_csin_template.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2016-10-14 00:12:56 +0000
committerJoseph Myers <joseph@codesourcery.com>2016-10-14 00:12:56 +0000
commite886c36771c1a941cdfc5c4df4dc85b3f8f6d4ef (patch)
tree835762fb453807749de2db0f78ef7bdea719a620 /math/s_csin_template.c
parent07c18a008c2ed8f5660adba2b778671db159a141 (diff)
downloadglibc-e886c36771c1a941cdfc5c4df4dc85b3f8f6d4ef.tar.gz
glibc-e886c36771c1a941cdfc5c4df4dc85b3f8f6d4ef.tar.xz
glibc-e886c36771c1a941cdfc5c4df4dc85b3f8f6d4ef.zip
Clean up some complex functions raising FE_INVALID.
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.
Diffstat (limited to 'math/s_csin_template.c')
-rw-r--r--math/s_csin_template.c11
1 files changed, 2 insertions, 9 deletions
diff --git a/math/s_csin_template.c b/math/s_csin_template.c
index 59d887693c..2fe0b157cb 100644
--- a/math/s_csin_template.c
+++ b/math/s_csin_template.c
@@ -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