# Large sum returns negative numbers in julia

**URL:** <https://discourse.julialang.org/t/large-sum-returns-negative-numbers-in-julia/49032>\
**Category:** General Usage\
**Tags:** integer-overflow\
**Created:** [October 26, 2020, 10:12am UTC](https://discourse.julialang.org/t/large-sum-returns-negative-numbers-in-julia/49032 "2020-10-26T10:12:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [October 26, 2020, 10:16am UTC](https://discourse.julialang.org/t/large-sum-returns-negative-numbers-in-julia/49032/2 "2020-10-26T10:16:42Z")

</div>

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

```julia
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](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

---

_[View the full topic](https://discourse.julialang.org/t/large-sum-returns-negative-numbers-in-julia/49032)._
