# Overflow behavior

**URL:** https://discourse.julialang.org/t/overflow-behavior/39924
**Category:** General Usage
**Created:** [May 22, 2020, 12:13am UTC](https://discourse.julialang.org/t/overflow-behavior/39924 "2020-05-22T00:13:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)
#### Post date: [May 22, 2020, 12:13am UTC](https://discourse.julialang.org/t/overflow-behavior/39924/1 "2020-05-22T00:13:40Z")

</div>

The manual reads _“In Julia, exceeding the maximum representable value of a given type results in a wraparound behavior”_ with an example along these lines:

```julia
julia> typemax(Int64)+1
-9223372036854775808

```

which does wrap around on 64-bit system, but other “smaller” integral types, e.g. `Int32`, `Int16`, etc. don’t overflow and wrap around:

```julia
julia> typemax(Int8)+1
256

```

Am I reading it wrong?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [May 22, 2020, 12:17am UTC](https://discourse.julialang.org/t/overflow-behavior/39924/2 "2020-05-22T00:17:23Z")

</div>

Literal constants like `1` are of the default `Int` type, which is `Int64` on a 64-bit machine. So, `typemax(Int8)+1` is an `Int8 + Int64`, which promotes the operands to `Int64` and hence does not overflow. You are thinking of:

```julia
julia> typemax(Int8) + Int8(1)
-128

```

---

<div class="post-metadata">

### Author: ![pauljurczak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauljurczak/32/921_2.png) [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)
#### Post date: [May 22, 2020, 12:18am UTC](https://discourse.julialang.org/t/overflow-behavior/39924/3 "2020-05-22T00:18:39Z")

</div>

Thanks. I was typing just that. 😀
