3 ms·
Floats have the same accuracy everywhere when measured in relative error, ints have the same accuracy everywhere when measuring absolutely. Which of those is b
by dmurray 1y ago
Floats have the same accuracy everywhere when measured in relative error, ints have the same accuracy everywhere when measuring absolutely.
Which of those is better? It depends on the application. All you can do is hope the person who gave you the numbers chose the more appropriate representation, the less painful way to lose fidelity in a representation of the real world. By converting to the other representation you now have lost that fidelity in both ways.
Again, by a similar argument to above, something like this has to be true. You have exactly 32 bits of information either way, and both conversions lose the same amount of information - you end up with a 32-bit representation, but it only represents a domain of 2^27 (or whatever it is) distinct numbers.
- nofriend 1y ago>both conversions lose the same amount of information This is exactly what's untrue. I said "orders of magnitude", but I could have said bits - they're analogous concepts. Ints with the high 9 bits set to zero lose no information when converting to single precision floating point. The rest lose progressively more information, concentrated in the low order bits, up to 8 bits. Certainly regrettable, but usually manageable. Converting from floats to ints might be representable exactly, but if the number is, say, near 1, then it will be rounded to 1, losing 23 bits of information. If the number is near 0 then it will be rounded to 0, losing 31 bits of information.