# Maximum value for Julia integer types

**URL:** <https://discourse.julialang.org/t/maximum-value-for-julia-integer-types/98373>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 5, 2023, 8:07am UTC](https://discourse.julialang.org/t/maximum-value-for-julia-integer-types/98373 "2023-05-05T08:07:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brinkhuis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brinkhuis/32/18752_2.png) [@Brinkhuis](https://discourse.julialang.org/u/Brinkhuis)\
**Post date:** [May 5, 2023, 8:07am UTC](https://discourse.julialang.org/t/maximum-value-for-julia-integer-types/98373/1 "2023-05-05T08:07:47Z")

</div>

Julia `Integer` types have a minimum and maximum [value](https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/).  
When calculations go beyond those boundaries, results are ‘incorrect’.

```julia
for i in Int8[5, 10, 15, 20]
    println(i, " -> ", i^2)
end

```

Result:

```
5 -> 25
10 -> 100
15 -> -31
20 -> -112

```

Question:

> _Is there an efficient way in Julia to raise an exception when this occurs?_  
> _This to prevent this from happening without noticing._

Maybe there are better solutions than raising an exception.

---

<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:** [May 5, 2023, 8:14am UTC](https://discourse.julialang.org/t/maximum-value-for-julia-integer-types/98373/2 "2023-05-05T08:14:11Z")

</div>

See

> [@Discussion about integer overflow](https://discourse.julialang.org/t/discussion-about-integer-overflow/69627):
>
> Yes, it is a limitation but I would not call it big since we could use BigInt if Int64 is not enough and an overflow is something we can catch. I find more worrying this: \> julia\> 1 / 10^20000 \> Inf I’d rather have an overflow here than Inf, or at least an Infinitesimal value… Maybe something we could ask for future versions of Julia.

and all the other discussions linked therein - it’s probably not productive to rehash this lenghty discussion.

One direct answer to your question is

> **[GitHub - JeffreySarnoff/SaferIntegers.jl: These integer types use checked...](https://github.com/JeffreySarnoff/SaferIntegers.jl)**
>
> These integer types use checked arithmetic, otherwise they are as system types. - GitHub - JeffreySarnoff/SaferIntegers.jl: These integer types use checked arithmetic, otherwise they are as system ...
