Jump to content
  • Advertisement
Sign in to follow this  
Bobboau

float bit format

This topic is 4877 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

is there a platform independent way of getting the elements of a float? as I understand a float might be defined diferently on diferent hardware. so I'd like a way of getting access to the diferent parts in a way that will work on all systems (and be a hell of a lot more readable) if I just wanted the radix or the sign, maybe some macro for extraction or a define/constant for were the diferent elements start/end.

Share this post


Link to post
Share on other sites
Advertisement
to get the sign all you have to do is check the high bit of the value you are looking at. If the high bit is a 1 then it is a negative number, if it's 0, positive. As for the radix, i'm not so sure...floats are compiler dependent so it really depends what you're working with. i think the norm is 23 places for significant numbers in a float, but i can't make any promises...

Share this post


Link to post
Share on other sites
Look into std::numeric_limits. Its defined in <limits>, and tells you a lot of the implementation defined specifics of the various number formats. If you want the specific values for a given variable, there's frexp in <cmath> It'll give the matissa and exponent for a given floating point value.

CM

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!