[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk compl()
From: |
Andrew J. Schorr |
Subject: |
Re: gawk compl() |
Date: |
Mon, 10 Oct 2005 09:29:55 -0400 |
User-agent: |
Mutt/1.4.1i |
Hi Karel,
On Mon, Oct 10, 2005 at 02:19:49PM +0200, Karel Zak wrote:
> $ gawk 'BEGIN {printf("%#x\n", compl(0xFFFF0000)) }'
> 0x1fffff0000ffff
>
> I see same output for 3.1.5, 3.1.4 and 3.1.3. It seems that version
> 3.1.2 returns correct output (it means 0xffff).
Actually, the code seems to be working correctly. Your code
relies on the assumption that the internal operation is working
on a 32-bit integer. But in fact, the code in builtin.c:do_compl()
is using a uintmax_t type for the calculations. And on my 32-bit x86
system, it is defined as follows:
typedef unsigned long long int uintmax_t;
So, in fact, the calculation is being done with 64 bits.
Therefore ~0xFFFF0000 = 0xFFFFFFFF0000FFFF. This is
then converted to floating point and gets truncated
in the process.
At the moment, all of the bitwise operators seem to be
implemented using uintmax_t. This is not really problematic
for the other operators, but it is certainly confusing
for compl()...
Regard,
Andy
- gawk compl(), Karel Zak, 2005/10/10
- Re: gawk compl(),
Andrew J. Schorr <=