N
news.aon.at
Hello,
I try to cast a constant value (-32766.5) to float and then to an unsigned
short.
Once directly and once with an intermediate variable.
unsigned short s=(unsigned short)((float)(-32766.5));
vs.
float f=((float)(-32766.5));
unsigned short s=(unsigned short)f;
I use different compilers for this:
a) IBM Visual Age 3.5 (very old, 1995)
b) Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for
80x86 (MS-C6)
c) Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for
80x86 (VS2010)
d) gcc version 2.95.2-6 19991024 (cygwin experimental)
e) mingw32-gcc (GCC) 3.4.5 (mingw special) [Copyright (C) 2004 Free Software
Foundation, Inc.]
f) WindRiver Vxw6.7 CrossCompiler: ccpentium (Wind River VxWorks G++
DWARF-EH 4.1-131) 4.1.2 [Copyright (C) 2006 Free Software Foundation, Inc.]
a,b,c,d : give 0x8002 in both cases.
e,f give 0 (!) in the first case and 0x8002 in the 2nd cases
??
Note : when i cast to a SHORT instead of an unsigned short in the first
case, ALL compilers give 0x8002
(cast to float to short to unsigned short)
unsigned short s=(short)((float)(-32766.5));
or
unsigned short s=(unsigned short)(short)((float)(-32766.5));
Any Comments?
I try to cast a constant value (-32766.5) to float and then to an unsigned
short.
Once directly and once with an intermediate variable.
unsigned short s=(unsigned short)((float)(-32766.5));
vs.
float f=((float)(-32766.5));
unsigned short s=(unsigned short)f;
I use different compilers for this:
a) IBM Visual Age 3.5 (very old, 1995)
b) Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for
80x86 (MS-C6)
c) Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for
80x86 (VS2010)
d) gcc version 2.95.2-6 19991024 (cygwin experimental)
e) mingw32-gcc (GCC) 3.4.5 (mingw special) [Copyright (C) 2004 Free Software
Foundation, Inc.]
f) WindRiver Vxw6.7 CrossCompiler: ccpentium (Wind River VxWorks G++
DWARF-EH 4.1-131) 4.1.2 [Copyright (C) 2006 Free Software Foundation, Inc.]
a,b,c,d : give 0x8002 in both cases.
e,f give 0 (!) in the first case and 0x8002 in the 2nd cases
??
Note : when i cast to a SHORT instead of an unsigned short in the first
case, ALL compilers give 0x8002
(cast to float to short to unsigned short)
unsigned short s=(short)((float)(-32766.5));
or
unsigned short s=(unsigned short)(short)((float)(-32766.5));
Any Comments?