3 ms·
If you want to simulate a galaxy, the smallest scale that you can resolve is much much larger than size*2^(-128). Since you need floating point arithmetic for m
by atakan_gurkan 15y ago
If you want to simulate a galaxy, the smallest scale that you can resolve is much much larger than size*2^(-128). Since you need floating point arithmetic for many other computations, increasing the precision in your coordinates will cost a lot of extra computing without any gain in accuracy.
When precision in coordinates becomes an issue, you make a transformation and use relative coordinates anyways.
- JabavuAdams 15y ago> When precision in coordinates becomes an issue, you make a transformation and use relative coordinates anyways. This. Celestia, for example uses 128 (64.64) fixed-point for positions. The nasty case in games is when you're subtracting positions to get a relative result. It's okay to store all positions as fixed point, and then return a float for the difference operator. In general, you're not simulating the whole large volume with the same fidelity. You might be simulating a certain volume around the camera.
- atakan_gurkan 15y agoMy apologies, I misunderstood the meaning of "simulation". I was thinking of a calculation where you compute the interactions between objects and evolve their positions and momenta accordingly. Celestia does not do this of course, it uses some time series where the coefficients are computed in advance. For these purposes using fixed point and/or integer arithmetic instead of floating points could be entirely appropriate, I do not know enough to form a preference.
- wladimir 15y agoWhy would you need floating point arithmetic for anything? You can do all mathematical operations with fixed point just as well. And using relative coordinates everywhere might not be practical either. I don't understand why you are defending using floating point for everything so hard? There are cases in which it is not a good choice.
- marshray 15y agoWhy would you need floating point arithmetic for anything? So let's say you have your 128-bit integer coordinates and now you want to do something useful with them. Like interpret them as a 3D vector and multiply by a typical transformation matrix. Now you have all these intermediate terms inside the matrix gaining and losing precision. Rotation elements are going to have a range of -1 to 1. Translation elements have a similar range as your input coordinate system. Scaling elements have an almost arbitrary range. You can't use a general purpose matrix library any more. You have to track down every little multiplication and addition and analyze it for precision loss. Many will need to be converted to least fixed point numbers. You can do all mathematical operations with fixed point just as well. Some things are much much better, some things are much much worse. For something like rotation, you're multiplying by -1.0 to 1.0. You might use 64.64 fixed point numbers for this, but then you've wasted half the bits of precision you paid for. Floating-point certainly has a lot of potential for surprising behavior. But it usually allows you to get reasonable accuracy from a naive combination of basic operations.
- jerf 15y ago100000ly / 2^64 = 51 meters and change. And your simulation is probably faster with appropriate int math than any float math will be. Transforming to relative coordinates doesn't solve all the problems; you do your local calculation with the improved precision, but presumably at some point you then throw that back away again when you translate back to the global coords.
- palish 15y ago"And your simulation is probably faster with appropriate int math than any float math will be." This isn't true for modern CPUs, especially if you use SIMD vector operations.