Different exponent results with Int64 and Float64

During a calculation, I realized the following two examples produce different results. This doesn’t match my intuition, because the first example defaults to Int64, and the second example defaults to Float64.

julia> (15000000 + 6371000)^3
2227832818647195136

julia> (15000000.0 + 6371000.0)^3
9.760555447811e21

Why do the two calculations produce different results? The first example defaults to Int64 when I check the type, and the calculation should be far far below the max Int64 value.

Nope, 2^{63} is about 10^{19}, and as the floating point calculation shows, the answer is bigger than that (more like 10^{22}).

6 Likes