bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Bug in gawk big num


From: arnold
Subject: Re: [bug-gawk] Bug in gawk big num
Date: Thu, 27 Sep 2018 05:56:10 -0600
User-agent: Heirloom mailx 12.4 7/29/08

Hi.

Thanks for the report. Please see the patch from Andy, below, that
should fix the issue.

Arnold

Luu Vinh Phuc <address@hidden> wrote:

> Hello,
>
> While checking this question on StackOverflow: HEX TO DEC conversion fail
> for more than 16 digits <https://stackoverflow.com/a/52485753/995714> I
> noticed that gawk often produces incorrect results
>
> I've written a script to check gawk result compared with bc, my own
> conversion script, perl and python. Without --bignum the output from gawk
> is always incorrect in the last few digits. If the --bignum option is
> included then it sometimes gives the correct output
>
> For example
>  - 0x2111137875433111111DDDAFC = 9081107480899480908591836275756896935919
> and gawk --bignum prints out 163738384160959209720665463548 but gawk prints
> out 163738384160959190955653595136
> - 0x361037073401E5313436BA5C23513A12311BDEF111DDDAFC
> = 1325629231319468729194135471538271631225145170600986008316 but gawk
> --bignum outputs 1325629231319468799563181404533249658969760453051956592640
> and gawk outputs 1325629231319468625338609541012756365721961447986632327168
>
> You can find my script to test and its result attached
>
> My gawk version:
>
> GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)
> Copyright (C) 1989, 1991-2016 Free Software Foundation.
>
> This program is free software; you can redistribute it and/or modify
> it under the terms of the GNU General Public License as published by
> the Free Software Foundation; either version 3 of the License, or
> (at your option) any later version.
>
> This program is distributed in the hope that it will be useful,
> but WITHOUT ANY WARRANTY; without even the implied warranty of
> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> GNU General Public License for more details.
>
> You should have received a copy of the GNU General Public License
> along with this program. If not, see http://www.gnu.org/licenses/.
>
> Kindly check it,
>
> Thanks & Best regards,
> *Luu Vinh Phuc*
> Tel: (+84) 932 167 522 <address@hidden>

And the patch from Andy:

diff --git a/mpfr.c b/mpfr.c
index b6e9c16..8478570 100644
--- a/mpfr.c
+++ b/mpfr.c
@@ -296,7 +296,7 @@ force_mpnum(NODE *n, int do_nondec, int use_locale)
        if (do_nondec)
                base = get_numbase(cp1, cpend - cp1, use_locale);
 
-       if (! mpg_maybe_float(cp1, use_locale)) {
+       if (base != 10 || ! mpg_maybe_float(cp1, use_locale)) {
                mpg_zero(n);
                errno = 0;
                mpg_strtoui(n->mpg_i, cp1, cpend - cp1, & ptr, base);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]