about summary refs log tree commit diff
path: root/sysdeps/ieee754/ldbl-128ibm/s_erfl.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2013-08-17 18:25:51 +0930
committerAlan Modra <amodra@gmail.com>2013-10-04 10:32:48 +0930
commit650ef4bd7976e36831cba22d838b567d3b5f6e8f (patch)
treecf3fc9761840792041ba623b931e925a3833386a /sysdeps/ieee754/ldbl-128ibm/s_erfl.c
parent765714cafcad7e6168518c61111f07bd955a9fee (diff)
downloadglibc-650ef4bd7976e36831cba22d838b567d3b5f6e8f.tar.gz
glibc-650ef4bd7976e36831cba22d838b567d3b5f6e8f.tar.xz
glibc-650ef4bd7976e36831cba22d838b567d3b5f6e8f.zip
PowerPC floating point little-endian [4 of 15]
http://sourceware.org/ml/libc-alpha/2013-08/msg00084.html

Another batch of ieee854 macros and union replacement.  These four
files also have bugs fixed with this patch.  The fact that the two
doubles in an IBM long double may have different signs means that
negation and absolute value operations can't just twiddle one sign bit
as you can with ieee864 style extended double.  fmodl, remainderl,
erfl and erfcl all had errors of this type.  erfl also returned +1 for
large magnitude negative input where it should return -1.  The hypotl
error is innocuous since the value adjusted twice is only used as a
flag.  The e_hypotl.c tests for large "a" and small "b" are mutually
exclusive because we've already exited when x/y > 2**120.  That allows
some further small simplifications.

	[BZ #15734], [BZ #15735]
	* sysdeps/ieee754/ldbl-128ibm/e_fmodl.c (__ieee754_fmodl): Rewrite
	all uses of ieee875 long double macros and unions.  Simplify test
	for 0.0L.  Correct |x|<|y| and |x|=|y| test.  Use
	ldbl_extract_mantissa value for ix,iy exponents.  Properly
	normalize after ldbl_extract_mantissa, and don't add hidden bit
	already handled.  Don't treat low word of ieee854 mantissa like
	low word of IBM long double and mask off bit when testing for
	zero.
	* sysdeps/ieee754/ldbl-128ibm/e_hypotl.c (__ieee754_hypotl): Rewrite
	all uses of ieee875 long double macros and unions.  Simplify tests
	for 0.0L and inf.  Correct double adjustment of k.  Delete dead code
	adjusting ha,hb.  Simplify code setting kld.  Delete two600 and
	two1022, instead use their values.  Recognise that tests for large
	"a" and small "b" are mutually exclusive.  Rename vars.  Comment.
	* sysdeps/ieee754/ldbl-128ibm/e_remainderl.c (__ieee754_remainderl):
	Rewrite all uses of ieee875 long double macros and unions.  Simplify
	test for 0.0L and nan.  Correct negation.
	* sysdeps/ieee754/ldbl-128ibm/s_erfl.c (__erfl): Rewrite all uses of
	ieee875 long double macros and unions.  Correct output for large
	magnitude x.  Correct absolute value calculation.
	(__erfcl): Likewise.
	* math/libm-test.inc: Add tests for errors discovered in IBM long
	double versions of fmodl, remainderl, erfl and erfcl.
Diffstat (limited to 'sysdeps/ieee754/ldbl-128ibm/s_erfl.c')
-rw-r--r--sysdeps/ieee754/ldbl-128ibm/s_erfl.c55
1 files changed, 27 insertions, 28 deletions
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_erfl.c b/sysdeps/ieee754/ldbl-128ibm/s_erfl.c
index 6a4475ed6b..c861c65ccf 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_erfl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_erfl.c
@@ -760,16 +760,16 @@ long double
 __erfl (long double x)
 {
   long double a, y, z;
-  int32_t i, ix, sign;
-  ieee854_long_double_shape_type u;
+  int32_t i, ix, hx;
+  double xhi;
 
-  u.value = x;
-  sign = u.parts32.w0;
-  ix = sign & 0x7fffffff;
+  xhi = ldbl_high (x);
+  GET_HIGH_WORD (hx, xhi);
+  ix = hx & 0x7fffffff;
 
   if (ix >= 0x7ff00000)
     {				/* erf(nan)=nan */
-      i = ((sign & 0xfff00000) >> 31) << 1;
+      i = ((uint32_t) hx >> 31) << 1;
       return (long double) (1 - i) + one / x;	/* erf(+-inf)=+-1 */
     }
 
@@ -778,7 +778,7 @@ __erfl (long double x)
       if (ix >= 0x4039A0DE)
 	{
 	/* __erfcl (x) underflows if x > 25.6283 */
-	  if (sign)
+	  if ((hx & 0x80000000) == 0)
 	    return one-tiny;
 	  else
 	    return tiny-one;
@@ -789,8 +789,9 @@ __erfl (long double x)
 	  return (one - y);
 	}
     }
-  u.parts32.w0 = ix;
-  a = u.value;
+  a = x;
+  if ((hx & 0x80000000) != 0)
+    a = -a;
   z = x * x;
   if (ix < 0x3fec0000)  /* a < 0.875 */
     {
@@ -814,7 +815,7 @@ __erfl (long double x)
       y = erf_const + neval (a, TN2, NTN2) / deval (a, TD2, NTD2);
     }
 
-  if (sign & 0x80000000) /* x < 0 */
+  if (hx & 0x80000000) /* x < 0 */
     y = -y;
   return( y );
 }
@@ -824,18 +825,18 @@ long double
 __erfcl (long double x)
 {
   long double y, z, p, r;
-  int32_t i, ix, sign;
-  ieee854_long_double_shape_type u;
+  int32_t i, ix;
+  uint32_t hx;
+  double xhi;
 
-  u.value = x;
-  sign = u.parts32.w0;
-  ix = sign & 0x7fffffff;
-  u.parts32.w0 = ix;
+  xhi = ldbl_high (x);
+  GET_HIGH_WORD (hx, xhi);
+  ix = hx & 0x7fffffff;
 
   if (ix >= 0x7ff00000)
     {				/* erfc(nan)=nan */
       /* erfc(+-inf)=0,2 */
-      return (long double) (((u_int32_t) sign >> 31) << 1) + one / x;
+      return (long double) ((hx >> 31) << 1) + one / x;
     }
 
   if (ix < 0x3fd00000) /* |x| <1/4 */
@@ -846,7 +847,8 @@ __erfcl (long double x)
     }
   if (ix < 0x3ff40000) /* 1.25 */
     {
-      x = u.value;
+      if ((hx & 0x80000000) != 0)
+	x = -x;
       i = 8.0 * x;
       switch (i)
 	{
@@ -891,7 +893,7 @@ __erfcl (long double x)
 	  y += C20a;
 	  break;
 	}
-      if (sign & 0x80000000)
+      if (hx & 0x80000000)
 	y = 2.0L - y;
       return y;
     }
@@ -899,10 +901,11 @@ __erfcl (long double x)
   if (ix < 0x405ac000)
     {
       /* x < -9 */
-      if ((ix >= 0x40220000) && (sign & 0x80000000))
+      if (hx >= 0xc0220000)
 	return two - tiny;
 
-      x = fabsl (x);
+      if ((hx & 0x80000000) != 0)
+	x = -x;
       z = one / (x * x);
       i = 8.0 / x;
       switch (i)
@@ -933,21 +936,17 @@ __erfcl (long double x)
 	  p = neval (z, RNr8, NRNr8) / deval (z, RDr8, NRDr8);
 	  break;
 	}
-      u.value = x;
-      u.parts32.w3 = 0;
-      u.parts32.w2 = 0;
-      u.parts32.w1 &= 0xf8000000;
-      z = u.value;
+      z = (float) x;
       r = __ieee754_expl (-z * z - 0.5625) *
 	__ieee754_expl ((z - x) * (z + x) + p);
-      if ((sign & 0x80000000) == 0)
+      if ((hx & 0x80000000) == 0)
 	return r / x;
       else
 	return two - r / x;
     }
   else
     {
-      if ((sign & 0x80000000) == 0)
+      if ((hx & 0x80000000) == 0)
 	return tiny * tiny;
       else
 	return two - tiny;