bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: A BUG of 64-bit integer addition


From: Steffen Schuler
Subject: Re: A BUG of 64-bit integer addition
Date: Fri, 18 Apr 2008 00:42:05 +0200

On Thu, 17 Apr 2008 11:21:58 +0800, PRC wrote:

<snip>
> The test script is:
> BEGIN {
>     a1 = 0x001ffffff0426d9b
>     b1 = 0x000000004392b6cc
>     c1 = a1+b1
>     a2 = 0xf0426d9b
>     b2 = 0x4392b6cc
>     c2 = a2+b2
>     printf("1 -- %16x + %16x = %16x\n", a1, b1, c1); printf("2 -- %16x +
>     %16x = %16x\n", a2, b2, c2);
> }
>
> The results of runing this script are: 1 --   1ffffff0426d9b +
> 4392b6cc =   20000033d52468 2 --         f0426d9b +         4392b6cc =
>      133d52467
>
> The first calculation is wrong.
<snip>

gawk uses internally the C-type double also for integer calculation with a
mantissa of 53 bit length.
(AMD Athlon, Linux, gcc 4.2.3, gawk-3.1.6a)
The result of your addition would need 54 bit.

As long as gawk uses the C-type double you have to live with this error.

--
Steffen


reply via email to

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