Jump to content
  • Advertisement

Archived

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

szinkopa

float vs double in C++

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

Have somebody any experience about the speed difference between using floats and using doubles for computing?

Share this post


Link to post
Share on other sites
Advertisement
a double is 64 bits long, which (as I''m sure you know) isn''t how 32-bit processors like to deal with data.

Hence, doubles are going to be slightly slower than floats, and you should only use doubles if you really need that much precision (most of the time, you don''t - but sometimes it''s important).

Doubles aren''t horribly slow, they''re just "not quite as fast" as floats.

Share this post


Link to post
Share on other sites
Thanks Etnu.
I have made a very simple sim. example, and the delta time (float) was so little, that it was treated as zero, and the object did not start moving

Share this post


Link to post
Share on other sites
I''m pretty sure that your typical modern CPU converts all floating point numbers to 80 bits internally, whether they''re 32-bit floats or 64-bit doubles. Thus, the only signifant performance issue is memory usage. If you have a ton of doubles, then you could potentially have twice as many floats in that memory. This could be important if dealing with the CPU cache, for example. However, if you''re not using a lot of them, and you do need precision, go ahead and use doubles. Besides, make it work first, then you can maybe worry about optimizing minor things like this. [No flames, please. It''s just a suggestion.]

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!