TL;DR The author is not suggesting you implement this in your game. He's telling you that the precision will be slow changing, but bad.
This means the float
you're using to track your game time would start at 2^32. Because setting the number that large to start with, whatever you add on to it in the next 136 years, won't change the exponent.
Though, the precision will remain constant, it doesn't mean it's better. The precision gets worse the larger the number. Starting with a large number just means that the precision won't change over the life of the counter, but the precision is worse than starting with a small number. If you started at 0
the exponent would change frequently at first, meaning the precision changes frequently.
Concrete example:
float twoToThirtyTwo = 4294967296;
float game_time_elapsed = twoToThirtyTwo;
float getTimeElapsed() {
return game_time_elapsed - twoToThirtyTwo;
}
I believe overall the article is suggesting using floats for time deltas (short/small time spans) and using int
s or long
s for time elapsed (long/large time spans).
The author suggests a change to the code above to make it usable, since it's currently an example of how you can have constant bad precision. Change to a double:
double twoToThirtyTwo = 4294967296;
double game_time_elapsed = twoToThirtyTwo;
double getTimeElapsed() {
return game_time_elapsed - twoToThirtyTwo;
}
That code should give a constant good precision (around 1 microsecond) for a long time.