# Is it a bug or I am doing something wrong?

**URL:** <https://discourse.julialang.org/t/is-it-a-bug-or-i-am-doing-something-wrong/119105>\
**Category:** New to Julia\
**Tags:** question, bug\
**Created:** [September 6, 2024, 7:57am UTC](https://discourse.julialang.org/t/is-it-a-bug-or-i-am-doing-something-wrong/119105 "2024-09-06T07:57:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hangita101](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hangita101/32/211811_2.png) [@hangita101](https://discourse.julialang.org/u/hangita101)\
**Post date:** [September 6, 2024, 7:57am UTC](https://discourse.julialang.org/t/is-it-a-bug-or-i-am-doing-something-wrong/119105/1 "2024-09-06T07:57:43Z")

</div>

I am going through Julia Documentation and in overflow section i get weird result,

```julia
julia> typemax(Int16)
32767

julia> x=typemax(Int16)
32767

julia> x+1
327671

julia> x + 1
327671
julia> 

```

EDIT:  
I restart my REPL and it works

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 6, 2024, 8:10am UTC](https://discourse.julialang.org/t/is-it-a-bug-or-i-am-doing-something-wrong/119105/2 "2024-09-06T08:10:31Z")

</div>

```julia
julia> i = typemax(Int16)
32767

julia> j = i + 1
32768

julia> typeof(j)
Int64

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 6, 2024, 8:13am UTC](https://discourse.julialang.org/t/is-it-a-bug-or-i-am-doing-something-wrong/119105/3 "2024-09-06T08:13:05Z")

</div>

```julia
julia> typemax(Int16) + 1
32768

```

I think you need to restart your Julia session. You may have overwritten some methods somewhere.

---

<div class="post-metadata">

**Author:** ![Paul\_Warburton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_warburton/32/206802_2.png) [@Paul\_Warburton](https://discourse.julialang.org/u/Paul_Warburton)\
**Post date:** [September 6, 2024, 8:59am UTC](https://discourse.julialang.org/t/is-it-a-bug-or-i-am-doing-something-wrong/119105/4 "2024-09-06T08:59:15Z")

</div>

It works fine for me, note when you add 1 to the Int16 maximum, x automatically becomes Int64  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/e/4e34b81fffbc04d84aa66c1abc6e0e03f556aeeb.png)

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [September 6, 2024, 10:49am UTC](https://discourse.julialang.org/t/is-it-a-bug-or-i-am-doing-something-wrong/119105/5 "2024-09-06T10:49:09Z")

</div>

> [@Paul\_Warburton](#):
>
> note when you add 1 to the Int16 maximum, x automatically becomes Int64

To add to @Paul_Warburton’s reply, as this behaviour might be somewhat confusing for newcomers, the reason is that `1` is an `Int64` (well, at least on 64-bit Julia).

```julia-repl
julia> typeof(1)
Int64

```

In the addition our `Int16` `typemax` will then get promoted to `Int64`, resulting in a sum of type `Int64`.

If you want to actually get an `Int16` overflow, you’ll need the `Int16` (or lower precision) version of `1`, e.g. via `one(Int16)` or `Int16(1)`.

```julia-repl
julia> typemax(Int16) + one(Int16)
-32768

```

---

<div class="post-metadata">

**Author:** ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Post date:** [September 6, 2024, 4:45pm UTC](https://discourse.julialang.org/t/is-it-a-bug-or-i-am-doing-something-wrong/119105/6 "2024-09-06T16:45:13Z")

</div>

For those wanting (one way) to replicate the OP’s results:

```julia-repl
julia> x + y = parse(Int, string(x, y))
+ (generic function with 1 method)

julia> typemax(Int16)
32767

julia> typemax(Int16) + 1
327671

```

😉  
(See this response and the post in general for more fun details: [A most harrowing collection of Julia WATs - #10 by Philogicatician](https://discourse.julialang.org/t/a-most-harrowing-collection-of-julia-wats/77323/10))
