about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-11-19 23:03:33 +0000
committerUlrich Drepper <drepper@redhat.com>1997-11-19 23:03:33 +0000
commitb038dd54b2930754b6e436e1ec13525d7b8bedee (patch)
treebf806b34a0c2e4a7127e4898540dd533916a5861
parente5000c7fc11f6b5bbc177aa1aca7b4969a3f7910 (diff)
downloadglibc-b038dd54b2930754b6e436e1ec13525d7b8bedee.tar.gz
glibc-b038dd54b2930754b6e436e1ec13525d7b8bedee.tar.xz
glibc-b038dd54b2930754b6e436e1ec13525d7b8bedee.zip
Use version fromglibc 2.1 which corrects several bugs.
-rw-r--r--misc/efgcvt.c6
-rw-r--r--misc/efgcvt_r.c99
2 files changed, 80 insertions, 25 deletions
diff --git a/misc/efgcvt.c b/misc/efgcvt.c
index 24d63176d0..4db0d84902 100644
--- a/misc/efgcvt.c
+++ b/misc/efgcvt.c
@@ -39,7 +39,8 @@ APPEND (FUNC_PREFIX, fcvt) (value, ndigit, decpt, sign)
 {
   static char buf[MAXDIG];
 
-  (void) fcvt_r (value, ndigit, decpt, sign, buf, sizeof buf);
+  (void) APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign,
+				       buf, sizeof buf);
 
   return buf;
 }
@@ -51,7 +52,8 @@ APPEND (FUNC_PREFIX, ecvt) (value, ndigit, decpt, sign)
 {
   static char buf[MAXDIG];
 
-  (void) ecvt_r (value, ndigit, decpt, sign, buf, sizeof buf);
+  (void) APPEND (FUNC_PREFIX, ecvt_r) (value, ndigit, decpt, sign,
+				       buf, sizeof buf);
 
   return buf;
 }
diff --git a/misc/efgcvt_r.c b/misc/efgcvt_r.c
index e6030c8543..7ad057fcb7 100644
--- a/misc/efgcvt_r.c
+++ b/misc/efgcvt_r.c
@@ -37,6 +37,9 @@
 #define FLOOR APPEND(floor, FLOAT_NAME_EXT)
 #define FABS APPEND(fabs, FLOAT_NAME_EXT)
 #define LOG10 APPEND(log10, FLOAT_NAME_EXT)
+#define EXP APPEND(exp, FLOAT_NAME_EXT)
+#define ISINF APPEND(isinf, FLOAT_NAME_EXT)
+#define ISNAN APPEND(isnan, FLOAT_NAME_EXT)
 
 
 int
@@ -54,9 +57,15 @@ APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, buf, len)
       return -1;
     }
 
-  *sign = value < 0.0;
-  if (*sign)
-    value = - value;
+  if (!ISINF (value) && !ISNAN (value))
+    {
+      /* OK, the following is not entirely correct.  -0.0 is not handled
+	 correctly but glibc 2.0 does not have a portable function to
+	 implement this test.  */
+      *sign = value < 0.0;
+      if (*sign)
+	value = -value;
+    }
 
   n = snprintf (buf, len, "%.*" FLOAT_FMT_FLAG "f", ndigit, value);
   if (n < 0)
@@ -66,16 +75,29 @@ APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, buf, len)
   while (i < n && isdigit (buf[i]))
     ++i;
   *decpt = i;
-  do
-    ++i;
-  while (! isdigit (buf[i]));
-  memmove (&buf[i - *decpt], buf, n - (i - *decpt));
+
+  if (i == 0)
+    {
+      /* Value is Inf or NaN.  */
+      *sign = 0;
+      return 0;
+    }
+
+  if (i < n)
+    {
+      do
+	++i;
+      while (i < n && !isdigit (buf[i]));
+      memmove (&buf[*decpt], &buf[i], n - i);
+      buf[n - (i - *decpt)] = 0;
+    }
 
   return 0;
 }
 
 #define weak_extern2(name) weak_extern (name)
 weak_extern2 (FLOOR) weak_extern2 (LOG10) weak_extern2 (FABS)
+weak_extern2 (EXP)
 
 int
 APPEND (FUNC_PREFIX, ecvt_r) (value, ndigit, decpt, sign, buf, len)
@@ -84,24 +106,55 @@ APPEND (FUNC_PREFIX, ecvt_r) (value, ndigit, decpt, sign, buf, len)
      char *buf;
      size_t len;
 {
-  FLOAT_TYPE (*log10_function) (FLOAT_TYPE) = &LOG10;
+  int exponent = 0;
 
-  if (log10_function)
-    {
-      /* Use the reasonable code if -lm is included.  */
-      ndigit -= (int) FLOOR (LOG10 (FABS (value)));
-      if (ndigit < 0)
-	ndigit = 0;
-    }
-  else
+  if (!ISNAN (value) && !ISINF (value) && value != 0.0)
     {
-      /* Slow code that doesn't require -lm functions.  */
-      FLOAT_TYPE d;
-      for (d = value < 0.0 ? - value : value;
-	   ndigit > 0 && d >= 10.0;
-	   d *= 0.1)
-	--ndigit;
+      FLOAT_TYPE (*log10_function) (FLOAT_TYPE) = &LOG10;
+
+      if (log10_function)
+	{
+	  /* Use the reasonable code if -lm is included.  */
+	  FLOAT_TYPE dexponent;
+	  dexponent = FLOOR (LOG10 (FABS (value)));
+	  value *= EXP (dexponent * -M_LN10);
+	  exponent = (int) dexponent;
+	}
+      else
+	{
+	  /* Slow code that doesn't require -lm functions.  */
+	  FLOAT_TYPE d;
+	  if (value < 0.0)
+	    d = -value;
+	  else
+	    d = value;
+	  if (d < 1.0)
+	    {
+	      do
+		{
+		  d *= 10.0;
+		  exponent--;
+		}
+	      while (d < 1.0);
+	    }
+	  else if (d >= 10.0)
+	    {
+	      do
+		{
+		  d *= 0.1;
+		  exponent++;
+		}
+	      while (d >= 10.0);
+	    }
+	  if (value < 0.0)
+	    value = -d;
+	  else
+	    value = d;
+	}
     }
 
-  return APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, buf, len);
+  if (APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit - 1, decpt, sign, buf, len))
+    return -1;
+  *decpt += exponent;
+  return 0;
 }