Reputation: 2441
I'm just experimenting with Julia and found that it gives incorrect value when run:
Input:
println(1000^6)
println(1000^7)
println(1000^8)
println(1000^9)
Output:
1000000000000000000
3875820019684212736
2003764205206896640
-6930898827444486144
Is this an issue or am I doing it wrong?
Upvotes: 2
Views: 1179
Reputation: 10982
As explained the problem is due to integer overflow. Maximum value you can store in an Int64 can be obtained thanks to
julia> typemax(Int64)
9223372036854775807
However, 1000^9
is bigger, as you can see with:
julia> BigInt(1000)^9
1000000000000000000000000000
Upvotes: 6