3 ms·
> Also for completeness it would be better to differentiate between int and float as float is imprecise due to rounding errors. Not true for most numbers. A 6
by mark-r 7y ago
> Also for completeness it would be better to differentiate between int and float as float is imprecise due to rounding errors.
Not true for most numbers. A 64-bit IEEE float can handle any 53-bit integer with no error at all.
- zeroimpl 7y agoIt can represent less than 0.1% of all 64-bit ints. That doesn’t seem like most to me.
- mark-r 7y agoI didn't claim 64-bit ints, I claimed 53-bit ints. How often do you use ints in the range from 54 to 64 bits? I'm willing to bet it's close to never. That's what I meant by "most". You have to consider the distribution.
- ben0x539 7y agorandomly generated IDs as 64 bit ints, pretty often. I mean, tweet IDs are up there too.
- ben0x539 7y agoAlmost all numbers aren't 53-bit integers (or smaller) :P
- mark-r 7y agoSince everybody feels like getting all pedantic on me, let me clarify what I was trying to say. Most of the integers you encounter in real life will be 53 bits or less, and can be held in an IEEE-754 64-bit float without introducing any error. It is not worth introducing a separate integer type for the exceptions, particularly when the language used as the basis of the format (Javascript) does not have an integer type.