This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix comparison in sqrtl for IBM long double 128


Hi,

This fixes the sqrtl code for the IBM long double 128. The following
testcase was used to verify this fix:

#include <math.h>
#include <stdio.h>

int main()
{
  long double x, y;
  long double sum, root;

  x = 0x1.c30000000029p-175;
  y = 0x1.49p+504;

  sum = x*x + y*y;
  root = sqrtl(sum);

  printf("root = %a\n", (double)root);

  return 0;
}

Before the fix, the output was "-inf", which is incorrect. Forcing a
signed comparison for "m" solves the problem and yields 0x1.49p+504.

The testsuite passes with no regressions for both 32-bit/64-bit ppc.


2010-11-10  Luis Machado  <luisgpm@br.ibm.com>

	* sysdeps/ieee754/ldbl-128ibm/e_sqrtl.c (__ieee754_sqrtl): Force
	  signed comparison.

diff --git a/sysdeps/ieee754/ldbl-128ibm/e_sqrtl.c b/sysdeps/ieee754/ldbl-128ibm/e_sqrtl.c
index 1f533ca..fe6bb55 100644
--- a/sysdeps/ieee754/ldbl-128ibm/e_sqrtl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/e_sqrtl.c
@@ -73,9 +73,9 @@ long double __ieee754_sqrtl(long double x)
 	m = ((a.i[2] >> 20) & 0x7ff) - 54;
       }
       m += n;
-      if (m > 0)
+      if ((int) m > 0)
 	a.i[2] = (a.i[2] & 0x800fffff) | (m << 20);
-      else if (m <= -54) {
+      else if ((int) m <= -54) {
 	a.i[2] &= 0x80000000;
 	a.i[3] = 0;
       } else {



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]