Large sum returns negative numbers in julia

This is integer overflow. Once the maximum integer number is hit, it will jump to the smallest:

julia> typemax(Int)
9223372036854775807

julia> typemax(Int)+1
-9223372036854775808

You can avoid this by using floats or BigInt.

There have been quite a few posts on this on this forum, search them for more details.

PS: please quote your code, see Please read: make it easier to help you

6 Likes