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: 17 Apr 2008 22:27:59 GMT
User-agent: Pan/0.132 (Waxed in Black)

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.

gawk uses internally the number type double also for integer calculation.
On my 64 bit Linux system (AMD Athlon) gcc 4.2.3 double has a mantissa of
53 bit length. The result of your addition has a length of 54 bit.

As long as gawk calculation is based on the C-type double, you have to 
live with this fault.

-- 
Steffen




reply via email to

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