4.2.3: mpf_set_str() no longer recognizes exponents with '+' prefix

Torbjorn Granlund tg at swox.com
Mon Aug 25 16:33:53 CEST 2008


Jan Andres <jandres at gmx.net> writes:

  Strings like "1e+3" are no more recognized by mpf_set_str() in 4.2.3,
  only "1e3" is. This is a bit troublesome as on the other hand,
  gmp_printf() and friends do output a '+'-prefixed exponent when using
  the "%g" format. See below for proposed fix.
  
  [OS, compiler info left out as this is a generic issue]
  
  
  --- gmp-4.2.3/mpf/set_str.c.orig	2007-12-10 05:47:18.000000000 +0100
  +++ gmp-4.2.3/mpf/set_str.c	2008-08-16 11:51:14.000000000 +0200
  @@ -274,7 +274,8 @@
         {
   	/* Scan and convert the exponent, in base exp_base.  */
   	long dig, neg = -(long) ('-' == expptr[0]);
  -	expptr -= neg;			/* conditional increment */
  +	if (neg || expptr[0] == '+')
  +	  expptr++;
   	c = (unsigned char) *expptr++;
   	dig = digit_value[c];
   	if (dig >= exp_base)
  
I made a slightly different fix.  Please try this and report back if
it work.

*** mpf/set_str.c	25 Aug 2008 14:09:29 -0000	1.5
--- mpf/set_str.c	25 Aug 2008 14:13:11 -0000	1.6
*************** mpf_set_str (mpf_ptr x, const char *str,
*** 275,280 ****
        {
  	/* Scan and convert the exponent, in base exp_base.  */
! 	long dig, neg = -(long) ('-' == expptr[0]);
! 	expptr -= neg;			/* conditional increment */
  	c = (unsigned char) *expptr++;
  	dig = digit_value[c];
--- 275,283 ----
        {
  	/* Scan and convert the exponent, in base exp_base.  */
! 	long dig, minus, plusminus;
! 	c = (unsigned char) *expptr;
! 	minus = -(long) (c == '-');
! 	plusminus = minus | -(long) (c == '+');
! 	expptr -= plusminus;			/* conditional increment */
  	c = (unsigned char) *expptr++;
  	dig = digit_value[c];
*************** mpf_set_str (mpf_ptr x, const char *str,
*** 294,298 ****
  	    dig = digit_value[c];
  	  }
! 	exp_in_base = (exp_in_base ^ neg) - neg; /* conditional negation */
        }
      else
--- 297,301 ----
  	    dig = digit_value[c];
  	  }
! 	exp_in_base = (exp_in_base ^ minus) - minus; /* conditional negation */
        }
      else

-- 
Torbjörn


More information about the gmp-bugs mailing list