Vasili Burdo on Thu, 16 Jul 2015 18:11:31 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Support of binary and hexadecimal integers in PARI/GP |
Hi, Bill >Do not trouble yourself, I did it already, see GIT branch bill-binary-hex. Thanks. See another patch in attachment for this branch - it fixes strtor() function. Had to introduce decimal-only function int_read_dec(), so for real numbers integer part is always parsed as decimal. And, looks like my changes for printing hex break functions concat() and default() - they become sensitive to base selected. For example, concat("abc"+123) returns "abc123" of decimal is used and "abc0x7b" if hex is used. Now I'm looking for a way to limit hex output to GP only. Please, do not apply patches I sent yesterday to MASTER. I'll post updated patch for MASTER later. Thanks, Vasili 2015-07-16 11:35 GMT+03:00 Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>: > On Thu, Jul 16, 2015 at 01:53:50AM +0300, Vasili Burdo wrote: >> >Even so, this is still worthwhile to do. >> Ok. Will deliver tomorrow. > > Do not trouble yourself, I did it already, see GIT branch > bill-binary-hex. > >> >I assume your patch was created to apply to PARI 2.7.4 ? >> No, it's for master - i.e. trunk. >> I'm new to git - work mostly w/ perforce and svn > > Your patch only applied to PARI 2.7.4 though, I had to forward port it. > >> >Your patch changes the result of strtoi >> Hm, could you point me to the test which fails? >> >> >? strtoi("0b111") >> >%1 = 7 >> >instead of 0. >> Hm, silent failure in basecase and something useful w/ my changes. >> Looks like my change is better :) > > Well, this is not a silent failure (it stop reading at the first non digit > character), but it happens it was not documented, so it is probably OK, though > the documentation of strtoi need to be updated. > > Cheers > Bill. >
diff --git a/src/language/anal.c b/src/language/anal.c index 1eed58f..9a3cc4d 100644 --- a/src/language/anal.c +++ b/src/language/anal.c @@ -653,6 +653,15 @@ real_read(pari_sp av, const char **s, GEN y, long prec) } static GEN +int_read_dec(const char **s) +{ + int nb; + GEN y = utoi(number(&nb, s)); + if (nb == MAX_DIGITS) y = int_read_more(y, s); + return y; +} + +static GEN int_read(const char **s) { int nb; @@ -666,8 +675,7 @@ int_read(const char **s) if (nb == MAX_XDIGITS) y = hex_read_more(y, s); } else { - y = utoi(number(&nb, s)); - if (nb == MAX_DIGITS) y = int_read_more(y, s); + y = int_read_dec(s); } return y; } @@ -679,7 +687,7 @@ GEN strtor(const char *s, long prec) { pari_sp av = avma; - GEN y = int_read(&s); + GEN y = int_read_dec(&s); y = real_read(av, &s, y, prec); if (typ(y) == t_REAL) return y; return gerepileuptoleaf(av, itor(y, prec));