[Bug c/13793] New: On 64 bit, casting neg value to unsigned long gives incorrect result
larue at cadence dot com
gcc-bugzilla@gcc.gnu.org
Wed Jan 21 18:18:00 GMT 2004
Take this simple C program
#include <stdio.h>
int main(int argc, char** argv)
{
double dummy = -5;
printf("The following lines should match:\n");
printf("double dummy = -5; (unsigned long) (dummy) = %lu \n", (unsigned
long) dummy);
printf("(unsigned long) (-5.0) = %lu \n", (unsigned
long) (-5.0));
}
gcc -m64 gcc64bitIntegerConversionBug.c
humdinger{ larue 187}:a.out
The following lines should match:
double dummy = -5; (unsigned long) (dummy) = 9223372036854775807
(unsigned long) (-5.0) = 18446744073709551611
If we don't use -m64 we get the right answers
humdinger{ larue 153}:a.out
The following lines should match:
double dummy = -5; (unsigned long) (dummy) = 4294967291
(unsigned long) (-5.0) = 4294967291
Here are the results using the Solaris native compiler:
humdinger{ larue 154}: cc -xarch=v9 gcc64bitIntegerConversionBug.c
"gcc64bitIntegerConversionBug.c", line 7: warning: conversion of double to
integral is out of range
humdinger{ larue 155}:a.out
The following lines should match:
double dummy = -5; (unsigned long) (dummy) = 18446744073709551611
(unsigned long) (-5.0) = 18446744073709551611
Here are the specifics on my environment:
humdinger{ larue 139}:uname -a
SunOS humdinger 5.7 Generic_106541-23 sun4u sparc SUNW,Ultra-4
humdinger{ larue 140}:g++ -v
Reading specs from /dv/tools/3rdParty/gcc/3.2/bin/../lib/gcc-lib/sparc-sun-
solaris2.7/3.2/specs
Configured with: ../configure --prefix= --enable-shared=libgcc,libstdc++ --
enable-threads --enable-languages=c,c++
Thread model: posix
gcc version 3.2
--
Summary: On 64 bit, casting neg value to unsigned long gives
incorrect result
Product: gcc
Version: 3.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: larue at cadence dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13793
More information about the Gcc-bugs
mailing list