Jump to content
  • Advertisement

Archived

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

Silly_con

float vs double vs long double

This topic is 5559 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
there are times where you don''t need to worry about it, and this is one of those times. use them and compare, and see the difference.


Current project: 2D in Direct3D engine.
% completed: ~35%
Status: Active.

Share this post


Link to post
Share on other sites
No but yes. There's no performance hit per sa, but doubles consume twice as much memory as floats, and long doubles are a litte bit bigger yet, and that can make accessing them slower if there is a lot of them.

Write your code using either templates or a typedef, then you can change it easily.

typedef float float_t;

And use float_t in your code.

[edited by - Magmai Kai Holmlor on March 31, 2003 9:12:07 PM]

Share this post


Link to post
Share on other sites
Floats are the fastest, there is definitely a performance hit when using larger floating point types such as double.

Floats are 32 bit, doubles are 64 bit, and I believe long doubles (80 bit) are not supported anymore by VC++ (its the same as double in the later versions).

Of course, the memory size difference is not that much of a problem, because with 512 megs of ram, you can store a very large amount of doubles. The performance problem comes from the fact that it takes more clock cycles to input a double into the FPU calculation units, so the calculations performed on doubles takes a good deal longer.

Which to use? It depends on what you want to do.... For position or vectors in a 3D game, I recommend floats, because alot of them are moved around in the memory, and there are a good deal of math operations performed on them. Some applications require more precision, this is where you use doubles.

A float can hold up to 6 significant digits, a double can hold about 16 significant digits.





Looking for a serious game project?
www.xgameproject.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You sure a float isn''t 7 digits and double 19?

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
You sure a float isn''t 7 digits and double 19?


Floating point numbers are not stored in base-10 representation, so no number of digits would accurately reflect the precision. Also, different architectures have different-sized floats and doubles, so you can''t say with any certainty.

If you feel like learning about how floating point numbers are stored, look for IEE-754 and IEEE-854.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
well i tend to prefer doubles, except for extremely speed sensative things. the accuray of floats is a joke: although they may have 6 digits (there seem to be 7 but the last has no accuracy at all), this is only when working with numbers between 1 and -1. if you input the number 1000.123456, it will probably be rounded to 1000.12 or something like that, getting worse with bigger numbers.

imagine a spacegame, where you have a galaxy of, say 100000 pixels wide: youd lose all your float accuracy at one side of this galaxy, imaging the effect...

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!