#1404 Unsigned 64bit Attribution from negative floating number

OTHER
closed
nobody
gcc (462)
out-of-date
Unknown
2013-01-30
2010-03-07
Anonymous
No

Accidentally I came across the strage behaviour when attributing a negative floating point number to a unsigned 64bit integer. For example, when attributing the value -1.0 to a 64bit integer instead of having the expected value (0xFFFF FFFF FFFF FFFF) the integer is attributed with the equivalent value if I used a 32bit value (0xFFFF FFFF). The attached file for test purposes is shown below:

#include <stdio.h>

int main ( )
{
unsigned long long i;
unsigned char* p;
float f;
int i2;

p = ( unsigned char* ) &i;
f = -1.0;
i2 = -1;

i = ( unsigned long long ) f;

printf ( "From floating point: " );

for ( int k = 0; k < sizeof ( i ); ++ k )
{
printf ( "%02X ", ( unsigned int ) p [k] );
}

printf ( "\r\n" );

i = ( unsigned long long ) i2;

printf ( "From signed integer: " );

for ( int k = 0; k < sizeof ( i ); ++ k )
{
printf ( "%02X ", ( unsigned int ) p [k] );
}

printf ( "\r\n" );
}

The output of this test is:

From floating point: FF FF FF FF 00 00 00 00
From signed integer: FF FF FF FF FF FF FF FF

Thank you,
I hope it helps
Denis

Discussion

  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2010-03-07

    Test file

     
    Attachments
  • Earnie Boyd

    Earnie Boyd - 2012-10-22
    • milestone: --> Aged_issue
    • status: open --> closed-out-of-date
     
  • Earnie Boyd

    Earnie Boyd - 2012-10-22

    Works for me with GCC 4.7.0.

     
  • Earnie Boyd

    Earnie Boyd - 2013-01-30
    • status: closed-out-of-date --> closed
    • resolution: --> out-of-date
    • category: --> Unknown
    • milestone: --> OTHER
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks