Skip to main content
GameDev.net gamedev.net
🔒 Locked

Typecasting floats..

Started by RWarden Jun 26, 2000 at 1:46 AM 2 replies 400+ views
Original Post
RWarden
RWarden
Hi, this is my first post here and I''m hoping somebody can help me with this little quirk I''ve run up against.. I have a char pointer to a big chunk of memory representing a file that''s been loaded into RAM. To get a value from this memory, I''ll combine the bytes and increment the pointer.. e.g., for a 16-bit integer, I''d use "MAKEWORD ( *ptr, *(ptr+1) ); ptr+=2;" The problem comes into play when I try to load a float. I tried typecasting a 32-bit integer, but that only results in x.0000000 (where X is the 32-bit integer). I''m surprised that I''m stumped at such a simple problem, but that''s the nature of being stumped. Thanks for any help. - RWarden (roberte@maui.net)
MK42
MK42
You might try memcpy() to copy four bytes from ptr to the address of the float variable.

- MK42
RotoMuffin
RotoMuffin
Also, you can always use a void pointer to defeat the translations that occur in a word to float typecast.

-RotoMuffin
Hway
Hway

float f = *( (float*) (charptr+charoffs) );

Should do the trick. Aren''t typecasts so beautiful?-)
~~~ "'impossible' is a word in the dictonary of fools" --Napoleon

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.