diff -c gmp/mpf/set_str.c:1.1.1.1 gmp/mpf/set_str.c:1.4
*** gmp/mpf/set_str.c:1.1.1.1	Wed May  8 09:11:09 1996
--- gmp/mpf/set_str.c	Thu Aug  8 13:27:45 1996
***************
*** 27,32 ****
--- 27,37 ----
  #include "gmp-impl.h"
  #include "longlong.h"
  
+ #define assert(true) do { if (!(true)) abort (); } while (0)
+ 
+ #define swapptr(xp,yp) \
+ do { mp_ptr _swapptr_tmp = (xp); (xp) = (yp); (yp) = _swapptr_tmp; } while (0)
+ 
  long int strtol _PROTO ((const char *, char **ptr, int));
  
  static int
***************
*** 159,172 ****
    xsize = str_size / __mp_bases[base].chars_per_limb + 2;
    {
      long exp_in_base;
!     mp_size_t rsize, msize;
      int cnt, i;
!     mp_ptr mp, xp, tp, rp;
!     mp_limb_t cy;
      mp_exp_t exp_in_limbs;
!     mp_size_t prec = x->_mp_prec;
      int divflag;
!     mp_size_t xxx = 0;
  
      mp = (mp_ptr) TMP_ALLOC (xsize * BYTES_PER_MP_LIMB);
      msize = mpn_set_str (mp, (unsigned char *) begs, str_size, base);
--- 164,176 ----
    xsize = str_size / __mp_bases[base].chars_per_limb + 2;
    {
      long exp_in_base;
!     mp_size_t ralloc, rsize, msize;
      int cnt, i;
!     mp_ptr mp, tp, rp;
      mp_exp_t exp_in_limbs;
!     mp_size_t prec = x->_mp_prec + 1;
      int divflag;
!     mp_size_t madj, radj;
  
      mp = (mp_ptr) TMP_ALLOC (xsize * BYTES_PER_MP_LIMB);
      msize = mpn_set_str (mp, (unsigned char *) begs, str_size, base);
***************
*** 179,184 ****
--- 183,197 ----
  	return 0;
        }
  
+     madj = 0;
+     /* Ignore excess limbs in MP,MSIZE.  */
+     if (msize > prec)
+       {
+ 	madj = msize - prec;
+ 	mp += msize - prec;
+ 	msize = prec;
+       }      
+ 
      if (expflag != 0)
        exp_in_base = strtol (str + 1, (char **) 0,
  			    decimal_exponent_flag ? 10 : base);
***************
*** 193,277 ****
        {
  	MPN_COPY (x->_mp_d, mp, msize);
  	x->_mp_size = negative ? -msize : msize;
! 	x->_mp_exp = msize;
  	TMP_FREE (marker);
  	return 0;
        }
  
! #if 1
!     rsize = (((mp_size_t) (exp_in_base / __mp_bases[base].chars_per_bit_exactly))
  	     / BITS_PER_MP_LIMB + 3);
! #else
!     count_leading_zeros (cnt, (mp_limb_t) base);
!     rsize = exp_in_base - cnt * exp_in_base / BITS_PER_MP_LIMB + 1;
! #endif
!     rp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB);
!     tp = (mp_ptr) TMP_ALLOC (rsize * BYTES_PER_MP_LIMB);
  
      rp[0] = base;
      rsize = 1;
- 
      count_leading_zeros (cnt, exp_in_base);
- 
      for (i = BITS_PER_MP_LIMB - cnt - 2; i >= 0; i--)
        {
  	mpn_mul_n (tp, rp, rp, rsize);
  	rsize = 2 * rsize;
  	rsize -= tp[rsize - 1] == 0;
! 	xp = tp; tp = rp; rp = xp;
  
  	if (((exp_in_base >> i) & 1) != 0)
  	  {
  	    cy = mpn_mul_1 (rp, rp, rsize, (mp_limb_t) base);
  	    rp[rsize] = cy;
  	    rsize += cy != 0;
  	  }
        }
  
      if (rsize > prec)
        {
! 	xxx += rsize - prec;
  	rp += rsize - prec;
  	rsize = prec;
        }
! #if 0
!     if (msize > prec)
!       {
! 	xxx -= msize - prec;
! 	mp += msize - prec;
! 	msize = prec;
!       }
! #endif
      if (divflag)
        {
  	mp_ptr qp;
! 	mp_limb_t qflag;
! 	mp_size_t xtra;
! 	if (msize <= rsize)
  	  {
! 	    /* Allocate extra limb for current divrem sematics. */
  	    mp_ptr tmp = (mp_ptr) TMP_ALLOC ((rsize + 1) * BYTES_PER_MP_LIMB);
  	    MPN_ZERO (tmp, rsize - msize);
  	    MPN_COPY (tmp + rsize - msize, mp, msize);
  	    mp = tmp;
! 	    xxx += rsize - msize;
  	    msize = rsize;
  	  }
  	count_leading_zeros (cnt, rp[rsize - 1]);
  	if (cnt != 0)
  	  {
  	    mpn_lshift (rp, rp, rsize, cnt);
  	    cy = mpn_lshift (mp, mp, msize, cnt);
  	    if (cy)
  	      mp[msize++] = cy;
  	  }
  	qp = (mp_ptr) TMP_ALLOC ((prec + 1) * BYTES_PER_MP_LIMB);
! 	xtra = prec - (msize - rsize);
! 	qflag = mpn_divrem (qp, xtra, mp, msize, rp, rsize);
! 	qp[prec] = qflag;
  	tp = qp;
! 	rsize = prec + qflag;
! 	exp_in_limbs = rsize - xtra - xxx;
        }
      else
        {
--- 206,284 ----
        {
  	MPN_COPY (x->_mp_d, mp, msize);
  	x->_mp_size = negative ? -msize : msize;
! 	x->_mp_exp = msize + madj;
  	TMP_FREE (marker);
  	return 0;
        }
  
!     ralloc = (((mp_size_t) (exp_in_base / __mp_bases[base].chars_per_bit_exactly))
  	     / BITS_PER_MP_LIMB + 3);
!     rp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB);
!     tp = (mp_ptr) TMP_ALLOC (ralloc * BYTES_PER_MP_LIMB);
  
      rp[0] = base;
      rsize = 1;
      count_leading_zeros (cnt, exp_in_base);
      for (i = BITS_PER_MP_LIMB - cnt - 2; i >= 0; i--)
        {
  	mpn_mul_n (tp, rp, rp, rsize);
  	rsize = 2 * rsize;
  	rsize -= tp[rsize - 1] == 0;
! 	swapptr (rp, tp);
  
  	if (((exp_in_base >> i) & 1) != 0)
  	  {
+ 	    mp_limb_t cy;
  	    cy = mpn_mul_1 (rp, rp, rsize, (mp_limb_t) base);
  	    rp[rsize] = cy;
  	    rsize += cy != 0;
  	  }
        }
  
+     radj = 0;
      if (rsize > prec)
        {
! 	radj += rsize - prec;
  	rp += rsize - prec;
  	rsize = prec;
        }
! 
      if (divflag)
        {
  	mp_ptr qp;
! 	mp_limb_t qlimb;
! 	if (msize < rsize)
  	  {
! 	    /* Pad out MP,MSIZE for current divrem semantics.  */
  	    mp_ptr tmp = (mp_ptr) TMP_ALLOC ((rsize + 1) * BYTES_PER_MP_LIMB);
  	    MPN_ZERO (tmp, rsize - msize);
  	    MPN_COPY (tmp + rsize - msize, mp, msize);
  	    mp = tmp;
! 	    madj -= rsize - msize;
  	    msize = rsize;
  	  }
  	count_leading_zeros (cnt, rp[rsize - 1]);
  	if (cnt != 0)
  	  {
+ 	    mp_limb_t cy;
  	    mpn_lshift (rp, rp, rsize, cnt);
  	    cy = mpn_lshift (mp, mp, msize, cnt);
  	    if (cy)
  	      mp[msize++] = cy;
  	  }
+ 
  	qp = (mp_ptr) TMP_ALLOC ((prec + 1) * BYTES_PER_MP_LIMB);
! 	qlimb = mpn_divrem (qp, prec - (msize - rsize), mp, msize, rp, rsize);
  	tp = qp;
! 	exp_in_limbs = qlimb + (msize - rsize) + (madj - radj);
! 	rsize = prec;
! 	if (qlimb != 0)
! 	  {
! 	    tp[prec] = qlimb;
! 	    /* Skip the least significant limb not to overrun the destination
! 	       variable.  */
! 	    tp++;
! 	  }
        }
      else
        {
***************
*** 282,292 ****
  	  mpn_mul (tp, mp, msize, rp, rsize);
  	rsize += msize;
  	rsize -= tp[rsize - 1] == 0;
! 	exp_in_limbs = rsize + xxx;
  
  	if (rsize > prec)
  	  {
- 	    xxx = rsize - prec;
  	    tp += rsize - prec;
  	    rsize = prec;
  	    exp_in_limbs += 0;
--- 289,298 ----
  	  mpn_mul (tp, mp, msize, rp, rsize);
  	rsize += msize;
  	rsize -= tp[rsize - 1] == 0;
! 	exp_in_limbs = rsize + madj + radj;
  
  	if (rsize > prec)
  	  {
  	    tp += rsize - prec;
  	    rsize = prec;
  	    exp_in_limbs += 0;

