Archived

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

float vs double in C++

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

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