3 ms·
Floating point numbers are suboptimal to represent timers. They use more bits than needed, aren't accurate on the bits they use, and require more effort for ope
by madez 9y ago
Floating point numbers are suboptimal to represent timers. They use more bits than needed, aren't accurate on the bits they use, and require more effort for operations.
Unsigned integers are better to represent timers. If the accuracy is 1/30s as in the example, then with a 32 bit unsigned integer you could cover over 55 days with perfect numerical accuracy and minimal computational effort. With 32 bit floating point numbers you get only 6 days, while needing to worry about accuracy and higher computational demand. At 64 bits it is 649936019 years for unsigned integers vs 8925512 years for floating point. If your game doesn't depend on state that is longer ago than the time covered, then using unsigned integers allows unlimited runtime.
Don't blindly use floats.
- pjc50 9y agoFloating point numbers are terrible at representing times and money quantities. Which is a shame given that Excel does it that way..