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: Wed, 26 Sep 2018 03:54:43 -0600
User-agent: Heirloom mailx 12.4 7/29/08

Hello.

I have not reviewed this in detail. Please see the gawk manual
https://www.gnu.org/software/gawk/manual/html_node/Arbitrary-Precision-Arithmetic.html#Arbitrary-Precision-Arithmetic
which discusses numeric calculations in great detail. Of particular note:

* By default gawk uses double precision hardware floating point for all
  calculations, so attempting to do arbitrarily large conversions
  is bound to fail.

* Even with MPFR (--bignum) the default precision remains the same as
  for hardware floating point so arbitrarily large conversions may
  still fail.

So, although I have not reviewed these scripts, my experience leads me
to believe that there aren't any bugs here, but rather incorrect use
of the MPFR facilities in gawk.

Thanks,

Arnold

L??u V??nh Ph??c <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>



reply via email to

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