4 ms·
> The real mystery is why most modern languages continue to use floats and integers as the default numeric types rather than some sort of BigDecimal representat
by amelius 3y ago
> The real mystery is why most modern languages continue to use floats and integers as the default numeric types rather than some sort of BigDecimal representation, given that precision and programmer intuitiveness trumps raw performance in the vast majority of cases.
It's also strange that people use floats to represent 3D coordinates. Why should coordinates closer to the origin of the scene have more precision than those further away?
- Joker_vD 3y agoWell, why should coordinates (and everything else, really) closer to the camera/player have more precision than those further away? And then you accidentally mix these two things together and here we are.
- amelius 3y agoI don't think many programs place the origin at the camera or player, and besides, what if you have more than one player?
- atq2119 3y agoAll 3D rasterization techniques ultimately put the camera at the origin. That's why you have different coordinate systems (model vs. world vs. view/camera) and transforms between them.
- amelius 3y agoYes, of course, but the coordinates in the original scene (before transformation) are typically done in floats. I also get that this is convenient, but the point is that it is not how a purist would do it.
- sk0g 3y agoBecause a lot of physics simulations and actor ticking is either reduced, or turned off entirely, when not within close proximity of the player. There are only so many CPU cycles in 1/60 seconds, so games have to be selective about what they update at full fidelity. (Single precision) float-induced rounding at large offsets would introduce a lot of jitter to these calculations, which looks and feels very janky.
- analog31 3y agoLife is kind of that way. For instance, I know the distance to my workplace more precisely than I know the distance to Alpha Centauri. But computations have to account for numeric precision. The course I took in numerical programming (aka "numerical analysis" in 1985) included an entire unit on the foibles of floating point numbers.
- amelius 3y agoHow would you write a game engine where one user is on Earth, and the other is around Alpha Centauri? Assuming the entire thing has to be modeled as a single world.
- analog31 3y agoDepends on what kind of user experience you're trying to program. For instance, the post office has multiple levels of precision -- state, city, street, etc., and managed to deliver the mail prior to the computer age. On the other hand, limitations of conventional floating point are imaginable, in which case you choose a different kind of numbering system. As it stands right now the typically cited value for the distance to Alpha Centauri doesn't take the position of the earth relative to the sun into account. We live with this imprecision. And in the post office example, a conventional address would be problematic because a person might move during the 8 year round trip between the stars.