2 ms·
> in a great many scenarios, you don't ever want a number bigger than will fit in a 64-bit int. You might think that, but remember that during math operations
by cratermoon 5y ago
> in a great many scenarios, you don't ever want a number bigger than will fit in a 64-bit int.
You might think that, but remember that during math operations the number of bits isn't all that matters, and even if your final result can fit in a 64-bit int, you can get errors in calculations when the intermediate results depend on needing extra precision.
- wongarsu 5y agoAdding at least a factor of two for safety is reasonable. So e.g. if you compute with 64-bit integers, you shouldn't ask if you ever need numbers larger than (2^64)-1, but if you need numbers larger than 2^62 (one bit for allowing signed ints, one for intermediates). That catches the most common examples like overflowing when calculating the average of two numbers or when calculating an offset. The less safety factor you have the more carefully you have to consider what your intermediates are doing. But going up one level of precision probably won't hurt performance too bad, if your language makes it easy (like 128-bit ints)