Maximum value for Julia integer types

Julia Integer types have a minimum and maximum value.
When calculations go beyond those boundaries, results are ‘incorrect’.

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.

See

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

One direct answer to your question is

3 Likes