Jump to content
  • Advertisement

Archived

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

HanSoL0

Floats vs. Doubles

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

If I use floaters hundreds of times in my program, vs. doubles hundreds of times, will this noticably affect the amount of memory that is used? Just a quickie I was pondering... Thanks, Ryan Buhr Reactor Interactive, LLC. www.reactorinteractive.net

Share this post


Link to post
Share on other sites
Advertisement
sizeof(float) typically is 32bits
sizeof(double) typically is 64bits

64-32 = 32

32 * hundreds = 32 hundreds


Doesn''t seem like a lot to me. Now if you say millions per second as a game may access, then the difference is it takes twice as long to load a double as it does a float because it''s twice as big.

Most 3D hardware uses 32bit floats as well, so a down converion would be wasteful.



Make a typedef, then you can try both easily.

/*
typedef float float_t;
/*/
typedef double float_t;
//*/

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Magmai Kai Holmlor
Make a typedef, then you can try both easily.

/*
typedef float float_t;
/*/
typedef double float_t;
//*/

My suggestion is on the name "Real" as in a real number.
/*
typedef float Real;
/*/
typedef double Real;
//*/
YMMV on whether it should be PascalCase or not.

Share this post


Link to post
Share on other sites
Depends what you use it for. If you are using it in OpenGL calls or the like then float is probably what you want, since the video card will use the float natively. For normal operations both are faster, as it depends entirely on what system you run it on. Unless you need double accuracy then just use float, since it will be easier on system memory either way.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''ve done a software-renderer and just swapping from floats to doubles increased the speed. It was compiled with VC++ 6 and tested on pII and pIII. I have really no clue on why it was faster. I actually belive it should have been slower. So...

/__fold

Share this post


Link to post
Share on other sites
doubles are faster than floats cause floats are converted into doubles.the only limitation is the size

"Tonight we strike,there is thunder in the sky,together we''ll fight,some of us will die,but they''ll always remember that we''ve made a stand and many will die by hand!" - ManOwaR

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sometimes using doubles can alow you to get rig of code that detects and takes care of round-off errors, and it can be a bust, i use floats for rendering, storage, and some real-time calculations that does need to be precise (tex coord or vectors), other stuff runs on doubles; polygon windings ops, BSP and such

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
quote:
Original post by Magmai Kai Holmlor
Make a typedef, then you can try both easily.

/*
typedef float float_t;
/*/
typedef double float_t;
//*/

My suggestion is on the name "Real" as in a real number.
/*
typedef float Real;
/*/
typedef double Real;
//*/
YMMV on whether it should be PascalCase or not.


...but it''s anything but a real number. A floating point number with infinite precision would be a real number.

Share this post


Link to post
Share on other sites
quote:
Original post by Magmai Kai Holmlor
...but it''s anything but a real number. A floating point number with infinite precision would be a real number.


Captain Pedantic strikes again!

Share this post


Link to post
Share on other sites
quote:
Original post by Magmai Kai Holmlor
quote:
Original post by Anonymous Poster
quote:
Original post by Magmai Kai Holmlor
Make a typedef, then you can try both easily.

/*
typedef float float_t;
/*/
typedef double float_t;
//*/

My suggestion is on the name "Real" as in a real number.
/*
typedef float Real;
/*/
typedef double Real;
//*/
YMMV on whether it should be PascalCase or not.


...but it''s anything but a real number. A floating point number with infinite precision would be a real number.


just like C/C++ ''int'' is anything but an integer. An integer number with infinite possible range would be a integer number.

Oh, and to counter-knit pick: the value contained by the proposed ''Real'' typedef would only hold ''Real'' values . (actually, that''s not true...but I''ll pretend it is).

(personally I''d vote ''real'' since it''s in style with ''int'', unless you''re using typedefs for ints too ).

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!