Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

RWarden

Typecasting floats..

This topic is 6623 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
Advertisement
You might try memcpy() to copy four bytes from ptr to the address of the float variable.

- MK42

Share this post


Link to post
Share on other sites

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

Should do the trick. Aren''t typecasts so beautiful?-)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!