Jump to content
  • Advertisement
Sign in to follow this  
hothead

please explain double

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

Advertisement
in c/c++, double is a very high precision floating point number. If you need many, many decimal places of accuracy, or expect obscene levels of magnitude, use double. Otherwise, use float. Common n00b error is to assume they always need double. You usually don't.

And if you really have to ask this here, you need to do a lot of reading before you write another line.

Share this post


Link to post
Share on other sites
Quote:
Original post by Pxtl
Common n00b error is to assume they always need double. You usually don't.


What is wrong with using double?
Common n00b error is to assume they always need optimization. You usually don't.

Thermo

Share this post


Link to post
Share on other sites
A float is 4 bytes, a double is 8 bytes. That's twice as much room for precision (and twice as much memory).

A float loses it's precision when trying to deal with larger numbers, because it starts to round and widdle away (called truncating) on it's decimals to make room for the more significant whole numbers on the left.

A number like 0.1934818098 will not be a problem for a float. However, a value like 139401834.5919183498 will, because to make room for the 139401834 on the left, it has to start rounding and truncating the values to the right, so you might end up with something like this: 139401834.591918. You've lost 4 numbers of precision, which will affect all future calculations with this number.

Do you understand now?

Share this post


Link to post
Share on other sites
Quote:
Original post by Konfusius
What is wrong with using double?


When used as function parameters, floats will fit in a register, doubles don't.

Share this post


Link to post
Share on other sites
Here is a page from MSDN with interesting numbers on it: Numerical Limits.

The most important ones are these:

FLT_DIG = 6
DBL_DIG = 15
Quote:
From MSDN
Number of digits, q, such that a floating-point number with q decimal digits can be rounded into a floating-point representation and back without loss of precision.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!