Makes sense, cause double can represent way bigger numbers than integers.
A double can represent numbers up to ± 1.79769313486231570x10^308, or roughly 18 with 307 zeroes behind it. You can’t fit that into a long, or even 128 bits. Even though rounding huge doubles is pointless, since only the first dozen digits or so are saved, using any kind of Integer would lead to inconsistencies, and thus potentially bugs.
How does that work? Is it just because double uses more bits? I’d imagine for the same number of bits, you can store more ints than doubles (assuming you want the ints to be exact values).
No, it has an exponent component: https://en.m.wikipedia.org/wiki/Double-precision_floating-point_format
No, I get that. I’m sure the programming language design people know what they are doing. I just can’t grasp how a double (which has to use at least 1 bit to represent whether or not there is a fractional component) can possibly store more exact integer vales than an integer type of the same length (same number of bits).
It just seems to violate some law of information theory to my novice mind.
Only to 2^54. The amount of integers representable by a long is more. But it can and does represent every int value correctly
*long long, if we’re gonna be taking about C types. A long is commonly limited to 32 bits.