lua-users home
lua-l archive

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


Jerome Vuarand wrote:
Here I get this:

% gcc --version
gcc (GCC) 3.4.4 (mingw special)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

% cat test.c
#include <stdio.h>

int main()
{
	printf("0x%08x\n", (int)(double)0xffffffff);
	printf("0x%08x\n", (int)(unsigned int)(double)0xffffffff);
	printf("%d\n", (int)(double)-4.0);
	printf("%d\n", (int)(unsigned int)(double)-4.0);
	return 0;
}
% make test
% test
0x7fffffff
0xffffffff
-4
0

As you can see with your additionnal unsigned int cast you lose all negative values. That's because (unsigned int)0xffffffff and (int)0xffffffff have two different representations in double precision floating point format.

I get different results in VS2005...

0xffffffff
0xffffffff
-4
-4

Perhaps there is a compiler setting for choosing the float rounding technique?

Brian