Jump to content
  • Advertisement

Archived

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

SKREAMZ

doubles and floats

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

i bet a similar question has been asked loads of times before but i can seem to find them even when using search, so im sorry in advance. for a huge 3D galaxy would the use of doubles be sufficient this? or would i have to split the galaxy into smaller sectors? thanks for your reply.

Share this post


Link to post
Share on other sites
Advertisement
Depends on your definition of huge, and depends on the resolution you want. If you want to track atoms in the area the size of the milky way, then no, doubles aren''t going to be good enough. But if you only want to track the centers of solar systems, then a double might work.

Share this post


Link to post
Share on other sites
For my space exploration game, after looking into the problem, I decided that I need 64 bits of precision if I didn't want to divide the universe up into sectors.

I am still looking at the sector option, however, since it will let me save a lot of bandwidth when pushing position/velocity/acceration packets if I could use doubles. Floats are not an option.

Correct me if I am wrong, but I believe that math with doubles or floats is equally fast in C/C++.




There's an interesting article at gamasutra that talks about this problem. The author suggests that the universe uses 142 bits of precision.


EDIT: If your game is massively multiplayer, you will likely need to sector it out anyway (unless you have a more advanced scheme for managing server bandwidth)

----------------------------------------
Let be be finale of seem, seems to me.
----------------------------------------

Shedletsky's Code Library:

Open source projects and demos



[edited by - Telamon on April 14, 2004 11:16:07 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Telamon
Correct me if I am wrong, but I believe that math with doubles or floats is equally fast in C/C++.



No, and yes, and no.

The first no is that C++ gives no performance guarantees on any operations. The speed of floating pointer arithmetic is by necessity platform dependent.

The yes is that on x86 processors, floats and doubles are both promoted to 80bits inside the floating point coprocessor when doing computations.

The second no is that floats are still half the size of doubles on x86 and so you have twice the memory movement cost for doubles that you do for floats, and for large data sets memory movement costs will tend to dominate over actual arithmetic operation costs.

Share this post


Link to post
Share on other sites
You could answer this question yourself.

There are 53 bits of precision in a double. Thus, for a distance of length N, the error will be N / 2^53.

There''s about 2^10 in each scale multiplication of 10e3, which means that you get about 10e(3*53/10) or about 10e15 magnitude difference (a little more, but this is a rough estimate).

How big is a galaxy? How precise measurements do you need? Divide the first by the second, and see if the result is less than 10e15 (good) or greater (bad).

Share this post


Link to post
Share on other sites
There are 150 million kilometers per Astronomical Unit (AU).
There are 63240 AU per light-year (LY).
The closest star to the sun is 4.3 LY away.
I don''t know how large galaxies are, but possibly they''re 100,000 LY across.

Therefore, the size of a galaxy may be 948600000000000000 kilometers across. That''s 948.6 quadrillion kilometers (1000 trillion = 1 quadrillion). In scientific notation, it''s 9.486 * 1017 km.

If you only are going to draw stars and not planets, you could ignore kilometers and use 1 unit = 1 AU. That would give you enough precision to have binary or trinary star systems and to revolve the multiple stars around each other, assuming they do that. Or you can just limit yourself to light-years, which is even easier.

If you do render planets, but not in greater detail than spheres, you can probably get away with ignoring kilometers. But for drawing planets up-close, like being able to land on them, you''d even need resolution at the centimeter level or so. To do this, you do indeed need to split things up into different coordinate scales.

~CGameProgrammer( );

Screenshots of your games or desktop captures -- Upload up to four 1600x1200 screenshots of your projects, registration optional. View all existing ones in the archives..

Share this post


Link to post
Share on other sites
quote:
Original post by Telamon
There's an interesting article at gamasutra that talks about this problem. The author suggests that the universe uses 142 bits of precision.



The way "error" works in the real universe is very strange. You might've heard of ΔxΔp ~ h (or something like that, my notes are 100km away). This means that the error in a measurement of position times the error in measurement of momentum is of the order of a small number h. Thus, I assert that the author, probably trying to simplify things, is wrong. If you were talking about position only you could measure that exactly (assuming perfect instruments), which implies ∞ bits of precision. It's only when you try to measure other things (whose operators don't commute, for those quantum physicists playing at home) that there enters some kind of error.

I rant about this kind of stuff too much.

[edited by - Doc on April 15, 2004 3:37:12 AM]

Share this post


Link to post
Share on other sites
thanks guys, ive decided after everything i read it would be easier to go with spliting the galaxy up into sectors.

Share this post


Link to post
Share on other sites
I wonder how many players would actually notice if you "accidentally" modelled the galaxy a few million times smaller (in proportion to star / planet size) than it actually is and with a few million times fewer stars?

Realism isn''t necessarily a good thing.

Look at where "Frontier" went - its space combat was crappy due to excessive realism. "Tie fighter" with its lame constant-speed physics was much more fun.

Mark

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!