# From Int64 to Int128

**URL:** <https://discourse.julialang.org/t/from-int64-to-int128/49322>\
**Category:** New to Julia\
**Created:** [October 30, 2020, 6:48pm UTC](https://discourse.julialang.org/t/from-int64-to-int128/49322 "2020-10-30T18:48:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RWS](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@RWS](https://discourse.julialang.org/u/RWS)\
**Post date:** [October 30, 2020, 6:48pm UTC](https://discourse.julialang.org/t/from-int64-to-int128/49322/1 "2020-10-30T18:48:16Z")

</div>

Hi there,  
I (as a noob) have a basic question:

```
x = typemax(Int32)
x = x + 1
typeof(x) 

```

i get Int64. So we go from Int32 to Int64

```
y = typemax(Int64)
y = y + 1

```

y now is -9223372036854775808

Why we cannot go to Int128? Does this depend on the system architecture?

Thx

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 30, 2020, 6:50pm UTC](https://discourse.julialang.org/t/from-int64-to-int128/49322/2 "2020-10-30T18:50:44Z")

</div>

It’s much simpler than this. 1 is an int64 (on 64 bit machines). Thus, when you add an int32 to an int64, you get an int64.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [October 30, 2020, 6:51pm UTC](https://discourse.julialang.org/t/from-int64-to-int128/49322/3 "2020-10-30T18:51:47Z")

</div>

Indeed

```julia
julia> typemax(Int32) + Int32(1)
-2147483648

```

and conversely,

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

```

Julia does not and will not do automatic widening of `Int` because that has gigantic, negative performance implications.

---

<div class="post-metadata">

**Author:** ![RWS](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@RWS](https://discourse.julialang.org/u/RWS)\
**Post date:** [October 30, 2020, 6:53pm UTC](https://discourse.julialang.org/t/from-int64-to-int128/49322/4 "2020-10-30T18:53:59Z")

</div>

Ouch… yes, ok

Thx a lot.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [October 30, 2020, 6:57pm UTC](https://discourse.julialang.org/t/from-int64-to-int128/49322/5 "2020-10-30T18:57:01Z")

</div>

One thing you can do is use a pacakge like [SaferIntegers.jl](https://github.com/JeffreySarnoff/SaferIntegers.jl)

```julia
julia> using SaferIntegers

julia> @saferintegers begin
           typemax(Int) + 1
       end
ERROR: OverflowError: 9223372036854775807 + 1 overflowed for type Int64
Stacktrace:
 [1] throw_overflowerr_binaryop(::Symbol, ::Int64, ::Int64) at ./checked.jl:154
 [2] checked_add at ./checked.jl:166 [inlined]
 [3] + at /home/mason/.julia/packages/SaferIntegers/lLDKG/src/arith_ops.jl:21 [inlined]
 [4] +(::Int64, ::SafeInt64) at /home/mason/.julia/packages/SaferIntegers/lLDKG/src/arith_ops.jl:71
 [5] top-level scope at REPL[31]:2

```

This way, these things are explicitly caught and you can use more appropriate number types.

---

<div class="post-metadata">

**Author:** ![RWS](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@RWS](https://discourse.julialang.org/u/RWS)\
**Post date:** [October 30, 2020, 7:12pm UTC](https://discourse.julialang.org/t/from-int64-to-int128/49322/6 "2020-10-30T19:12:33Z")

</div>

Amazing… thank you too
