This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/4835: Big = (unsigned long long)value; sets big (an unsigned long long) to zero if value is a float or double with a negative value
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/4835: Big = (unsigned long long)value; sets big (an unsigned long long) to zero if value is a float or double with a negative value
- From: ted_rossin at agilent dot com
- Date: 8 Nov 2001 19:28:17 -0000
- Reply-To: ted_rossin at agilent dot com
>Number: 4835
>Category: c++
>Synopsis: Big = (unsigned long long)value; sets big (an unsigned long long) to zero if value is a float or double with a negative value
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Nov 08 11:36:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Ted Rossin
>Release: unknown-1.0
>Organization:
>Environment:
HP-UX poophead B.10.20 A 9000/785 2007526995 two-user license
gcc-core-2.95.2.tar.gz and gcc-g++-2.95.2.tar.gz
>Description:
The program below generates the following output:
The value is 0x0000000000000000
The value is 0xfffffffffffffe62
The value is 0xfffffe62
The problem is that a negative float or double cast to an unsigned long long is set to zero instead of the negative value. If a negative float or double is cast to an unsigned long it behaves as expected.
--------------------------------------------------------
main()
{
double value;
unsigned long long Big;
int hey;
unsigned long ulong;
value = -414.0;
hey = 10;
Big = (unsigned long long)value;
printf("The value is 0x%016llx\n",Big);
Big = (unsigned long long)((long long)value);
printf("The value is 0x%016llx\n",Big);
ulong = (unsigned long)value;
printf("The value is 0x%08x\n",ulong);
}
>How-To-Repeat:
compile and run the program.
>Fix:
The workaround is to cast to an long long before casting to an unsigned long long.
Big = (unsigned long long)((long long)value);
>Release-Note:
>Audit-Trail:
>Unformatted: