Jump to content
  • Advertisement
Sign in to follow this  

Floating max number

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

Hi. Im thinking of comparing a pixel = meter. It's a car game. So if it is moving like 100 m/s, it will move 100 pixels per second. I'd like to know if it is too exagerated so the floating variables that hold the position values, will get to it max value too quickly.. In first of all, what is the range of a floating variable? I searched and found this: 3.4e +/- 38 (7 digits) what this means? 3.4 x10^38 ? It hols more then an integer? So, what is the best I can do in this situation? Should I change the comparison and put something like 1meter = 0.1 pixel ? thanks

Share this post

Link to post
Share on other sites
Yep, it's about 3.402823466e+38, which is approx. 3.4x10^38 as you said.

In your case, I really doubt that you need higher precision unless you're going to use gigantic worlds.

A light year is approximately 9.46x10^15 meters. So a floating point number's maximum value interpreted as meters would be about ~3.6x10^22 light years. The observable universe is only about ~100 billion light years across.

However, this is the wrong way to look at it. At large numbers, floating point numbers lose more and more accuracy. It just depends on how much accuracy you are willing to sacrifice.

This table from an article on Ageia's website explains it quite nicely:

Distance from origin (world units) Smallest detail size (world units)
1 0.0000001192092895
10 0.000000953674316
100 0.00000762939453
1,000 0.0000610351562
10,000 0.0009765625
100,000 0.0078125
1,000,000 0.0625
10,000,000 1.00
100,000,000 8.00
1,000,000,000 64.0
10,000,000,000 1024

Going by that table, if you measure everything in meters, once your car gets about 10,000 kilometers from the world origin you'll have a minimum of about 1 pixel inaccuracy.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!