[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk -M using int() changes results
From: |
arnold |
Subject: |
Re: gawk -M using int() changes results |
Date: |
Sun, 21 Jul 2024 12:13:56 -0600 |
User-agent: |
Heirloom mailx 12.5 7/5/10 |
Hi.
Thanks for the report. It's not really a bug. Instead, you need to
increase the precision of the floating point values used. I found
that setting PREC = 65 caused your example to work, but you may need
more precision as your numbers get bigger.
$ cat intbug.awk
BEGIN {
PREC = 65
N = 123456789101112131415;
print int( N / 10 );
print ( N - N % 10 ) / 10;
}
$ ./gawk -M -f intbug.awk
12345678910111213141
12345678910111213141
Thanks,
Arnold
João Oliveira <joao.souza@pucrs.br> wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS: -g -O2 -DNDEBUG
> uname output: Linux caliope 5.15.0-116-generic #126~20.04.1-Ubuntu SMP Mon
> Jul 1 15:40:07 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
>
> Gawk Version: 5.3.0
>
> Attestation 1:
> I have read
> https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
> Yes
>
> Attestation 2:
> I have not modified the sources before building gawk.
> True
>
> Description:
> When gawk -M is used, int() seems to be unable to cope properly with
> numbers that are "too big", possibly bigger than a 64-bit integer.
>
> I was using large numbers and wanted to do something like
>
> n = int( n / 10 ) // remove last decimal digit
>
> and at a certain size results started to be wrong. On the other hand,
> doing
>
> n = ( n - n % 10 ) / 10 // remove last decimal digit
>
> works properly.
> I was unable to find whether this is a known and accepted effect or a
> real bug, so I decided to report it anyway.
>
> Repeat-By:
>
> run gawk -M with
>
> BEGIN {
> N = 123456789101112131415;
> print int( N / 10 );
> print ( N - N % 10 ) / 10;
> }
>