about summary refs log tree commit diff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/fpioconst.h9
-rw-r--r--stdlib/strtod.c44
2 files changed, 33 insertions, 20 deletions
diff --git a/stdlib/fpioconst.h b/stdlib/fpioconst.h
index 8edbdccb17..309660ced6 100644
--- a/stdlib/fpioconst.h
+++ b/stdlib/fpioconst.h
@@ -1,5 +1,5 @@
 /* Header file for constants used in floating point <-> decimal conversions.
-Copyright (C) 1995 Free Software Foundation, Inc.
+Copyright (C) 1995, 1996 Free Software Foundation, Inc.
 This file is part of the GNU C Library.
 
 The GNU C Library is free software; you can redistribute it and/or
@@ -48,5 +48,12 @@ struct mp_power
   };
 extern const struct mp_power _fpioconst_pow10[LDBL_MAX_10_EXP_LOG + 1];
 
+/* The constants in the array `_fpioconst_pow10' have an offset.  */
+#if BITS_PER_MP_LIMB == 32
+# define _FPIO_CONST_OFFSET	2
+#else
+# define _FPIO_CONST_OFFSET	1
+#endif
+
 
 #endif	/* fpioconst.h */
diff --git a/stdlib/strtod.c b/stdlib/strtod.c
index 1a2d1aaf38..1a663ba3ab 100644
--- a/stdlib/strtod.c
+++ b/stdlib/strtod.c
@@ -65,10 +65,10 @@ extern FLOAT MPN2FLOAT (mp_srcptr mpn, int exponent, int negative);
 /* Definitions according to limb size used.  */
 #if	BITS_PER_MP_LIMB == 32
 #  define MAX_DIG_PER_LIMB	9
-#  define MAX_FAC_PER_LIMB	1000000000L
+#  define MAX_FAC_PER_LIMB	1000000000UL
 #elif	BITS_PER_MP_LIMB == 64
 #  define MAX_DIG_PER_LIMB	19
-#  define MAX_FAC_PER_LIMB	10000000000000000000L
+#  define MAX_FAC_PER_LIMB	10000000000000000000UL
 #else
 #  error "mp_limb size " BITS_PER_MP_LIMB "not accounted for"
 #endif
@@ -84,7 +84,7 @@ static const mp_limb _tens_in_limb[MAX_DIG_PER_LIMB + 1] =
 	       ,	  10000000000,          100000000000,
      1000000000000,       10000000000000,       100000000000000,
      1000000000000000,    10000000000000000,    100000000000000000,
-     1000000000000000000, 10000000000000000000
+     1000000000000000000, 10000000000000000000U
 #endif
 #if BITS_PER_MP_LIMB > 64
   #error "Need to expand tens_in_limb table to" MAX_DIG_PER_LIMB
@@ -128,7 +128,7 @@ round_and_return (mp_limb *retval, int exponent, int negative,
 	  return 0.0;
 	}
 
-      more_bits |= (round_limb & ((1 << round_bit) - 1)) != 0;
+      more_bits |= (round_limb & ((((mp_limb) 1) << round_bit) - 1)) != 0;
       if (shift == MANT_DIG)
 	/* This is a special case to handle the very seldom case where
 	   the mantissa will be empty after the shift.  */
@@ -166,25 +166,26 @@ round_and_return (mp_limb *retval, int exponent, int negative,
       exponent = MIN_EXP - 2;
     }
 
-  if ((round_limb & (1 << round_bit)) != 0
+  if ((round_limb & (((mp_limb) 1) << round_bit)) != 0
       && (more_bits || (retval[0] & 1) != 0
-          || (round_limb & ((1 << round_bit) - 1)) != 0))
+          || (round_limb & ((((mp_limb) 1) << round_bit) - 1)) != 0))
     {
       mp_limb cy = __mpn_add_1 (retval, retval, RETURN_LIMB_SIZE, 1);
 
       if (((MANT_DIG % BITS_PER_MP_LIMB) == 0 && cy) ||
           ((MANT_DIG % BITS_PER_MP_LIMB) != 0 &&
            (retval[RETURN_LIMB_SIZE - 1]
-            & (1 << (MANT_DIG % BITS_PER_MP_LIMB))) != 0))
+            & (((mp_limb) 1) << (MANT_DIG % BITS_PER_MP_LIMB))) != 0))
 	{
 	  ++exponent;
 	  (void) __mpn_rshift (retval, retval, RETURN_LIMB_SIZE, 1);
-	  retval[RETURN_LIMB_SIZE - 1] |= 1 << ((MANT_DIG - 1)
-						% BITS_PER_MP_LIMB);
+	  retval[RETURN_LIMB_SIZE - 1]
+	    |= ((mp_limb) 1) << ((MANT_DIG - 1) % BITS_PER_MP_LIMB);
 	}
       else if (exponent == MIN_EXP - 2
 	       && (retval[RETURN_LIMB_SIZE - 1]
-		   & (1 << ((MANT_DIG - 1) % BITS_PER_MP_LIMB))) != 0)
+		   & (((mp_limb) 1) << ((MANT_DIG - 1) % BITS_PER_MP_LIMB)))
+	       != 0)
 	  /* The number was denormalized but now normalized.  */
 	exponent = MIN_EXP - 1;
     }
@@ -628,14 +629,15 @@ INTERNAL (STRTOF) (nptr, endptr, group)
 		  /* FIXME: not the whole multiplication has to be done.
 		     If we have the needed number of bits we only need the
 		     information whether more non-zero bits follow.  */
-		  if (numsize >= ttab->arraysize - 2)
+		  if (numsize >= ttab->arraysize - _FPIO_CONST_OFFSET)
 		    cy = __mpn_mul (pdest, psrc, numsize,
-				    &ttab->array[2], ttab->arraysize - 2);
+				    &ttab->array[_FPIO_CONST_OFFSET],
+				    ttab->arraysize - _FPIO_CONST_OFFSET);
 		  else
-		    cy = __mpn_mul (pdest, &ttab->array[2],
-				    ttab->arraysize - 2,
+		    cy = __mpn_mul (pdest, &ttab->array[_FPIO_CONST_OFFSET],
+				    ttab->arraysize - _FPIO_CONST_OFFSET,
 				    psrc, numsize);
-		  numsize += ttab->arraysize - 2;
+		  numsize += ttab->arraysize - _FPIO_CONST_OFFSET;
 		  if (cy == 0)
 		    --numsize;
 		  SWAP (psrc, pdest);
@@ -788,13 +790,17 @@ INTERNAL (STRTOF) (nptr, endptr, group)
 	    neg_exp ^= expbit;
 
 	    if (densize == 0)
-	      memcpy (psrc, &ttab->array[2],
-		      (densize = ttab->arraysize - 2) * sizeof (mp_limb));
+	      {
+		densize = ttab->arraysize - _FPIO_CONST_OFFSET;
+		memcpy (psrc, &ttab->array[_FPIO_CONST_OFFSET],
+			densize * sizeof (mp_limb));
+	      }
 	    else
 	      {
-		cy = __mpn_mul (pdest, &ttab->array[2], ttab->arraysize - 2,
+		cy = __mpn_mul (pdest, &ttab->array[_FPIO_CONST_OFFSET],
+				ttab->arraysize - _FPIO_CONST_OFFSET,
 				psrc, densize);
-		densize += ttab->arraysize - 2;
+		densize += ttab->arraysize - _FPIO_CONST_OFFSET;
 		if (cy == 0)
 		  --densize;
 		SWAP (psrc, pdest);