[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Bug in gawk big num
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] Bug in gawk big num |
Date: |
Wed, 26 Sep 2018 09:40:49 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Wed, Sep 26, 2018 at 08:41:55AM -0400, Andrew J. Schorr wrote:
> On Wed, Sep 26, 2018 at 12:41:53PM +0700, Lưu Vĩnh Phúc wrote:
> > You can find my script to test and its result attached
>
> One quick comment about this: the problem here seems to be in the strtonum
> function. If you modify checkresult.sh like so:
>
> --- checkresult.sh 2018-09-26 08:32:16.469895260 -0400
> +++ cr.sh 2018-09-26 08:34:27.506910803 -0400
> @@ -105,8 +105,8 @@ while read -r v; do
> hex2dec_res=$(hex2dec $v)
> perl_res=$(perl -Mbignum -le "print hex '$v'")
> python_res=$(python -c "print int('$v', 16)")
> - gawkbignum_res=$(gawk --bignum -v n=0x$v 'BEGIN {print strtonum(n)}')
> - gawk_res=$(gawk -v n=0x$v 'BEGIN {print strtonum(n)}')
> + gawkbignum_res=$(gawk --bignum "BEGIN {print 0x$v+0}")
> + gawk_res=$(gawk "BEGIN {print 0x$v+0}")
>
> echo -ne "\n----------- $v:"
> echo -ne "\n bc: $bc_res"
>
> Then all of the gawk --bignum errors will disappear (but the plain
> gawk_res values do not change).
>
> So this leaves the question of why strtonum does not work as expected.
> I guess there may be a bug in mpfr.c:do_mpfr_strtonum, but don't have time
> to dig deeper right now...
I think the bug is in mpfr.c:mpg_maybe_float in this section:
for (; *s != '\0'; s++) {
if (*s == dec_point || *s == 'e' || *s == 'E')
return true;
}
If the hex string contains the letter 'E', it decides that it might be a
floating point number and ends up calling mpfr_strtofr instead
of mpg_strtoui.
Regards,
Andy
Re: [bug-gawk] Bug in gawk big num, arnold, 2018/09/26
Re: [bug-gawk] Bug in gawk big num, arnold, 2018/09/27