[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GAWK adding big numbers wrong
From: |
Aharon Robbins |
Subject: |
Re: GAWK adding big numbers wrong |
Date: |
Mon, 13 May 2002 01:29:38 +0300 |
Greetings. You have hit a limitation in hardware floating point. Gawk
uses double precision floating point numbers. The fact that the
calculator tool works doesn't prove anything about the hardware.
I suggest that if you need infinite precision, you use dc or bc.
Sorry.
Arnold Robbins
> From: "Bernd Schueller" <address@hidden>
> To: <address@hidden>
> Cc: <address@hidden>
> Subject: GAWK adding big numbers wrong
> Date: Sat, 11 May 2002 18:34:07 +0200
>
> Hello,
>
> When calculating _big_ numbers with 'gawk' I get wrong results with
> numbers larger than 53 bits (dec. > 9007199254740991)!
>
> The program:
> ---
> gawk -v sum=1 '
> BEGIN {
> for (i=1 ; i<57; i++)
> {printf("bit: %d\tvalue: %.f\tsum of %d bits:\t%.f\n" , i, sum, i,
> summe+=sum) ; sum=sum*2}
> }
> '
> ---
>
> generates:
> ...
> bit: 52 value: 2251799813685248 sum of 52 bits: 4503599627370495
> bit: 53 value: 4503599627370496 sum of 53 bits: 9007199254740991
> bit: 54 value: 9007199254740992 sum of 54 bits: 18014398509481984 *WRONG*
> bit: 55 value: 18014398509481984 sum of 55 bits: 36028797018963968
> ...
>
> The program:
> ---
> gawk ' BEGIN { for (i=9007199254740988 ; i<9007199254740994 ; i++) printf
> "%.f\n",i } '
> ---
>
> results in an infinite loop, continiously printing: 9007199254740992.
>
>
> I am using 'GNU Awk 3.0.4' from the 'Cygwin Package' on a Windows system:
>
> Package Version
> bash 2.05a-3
> gawk 3.0.4-1
>
> System is:
> Microsoft Windows 98 4.10.2222 A
> GenuineIntel x86 Family 6 Model 8 Stepping 6 (Celeron 700MHz)
> FPU built-in
>
>
> I do not suggest a CPU/FPU or Win98 problem, as I can add up the numbers
> correctly using the calculator tool from the Win98 menue...?!
>
>
> Thank you!
>
> Best regards
> bs
> --
> Bernhard Schueller
> Tilsiter Weg 4
> D-68723 Schwetzingen
> mailto:address@hidden
>
>
>