title: Understanding Julia Int overflow behaviour
body: <p>Coming from a Python / Matlab background, I'd like to understand better how Julia's Int64 overflow behaviour works.</p>
  <p>From the <a href="https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/#Overflow-behavior" rel="nofollow noreferrer">documentation</a>:</p>
  <blockquote>
  <p>In Julia, exceeding the maximum representable value of a given type
  results in a wraparound behavior.</p>
  </blockquote>
  <pre><code>julia&gt; x = typemax(Int64)
  9223372036854775807
  
  julia&gt; x + 1
  -9223372036854775808
  </code></pre>
  <p>Now, I did some experiments with numbers obviously larger than typemax(Int64), but the behaviour I see isn't consistent with the documentation. It seems like things don't always just wrap around. Is only a single wraparound allowed?</p>
  <pre><code>julia&gt; x = (10^10)^(10^10)
  0
  julia&gt; x = 10^10^10^10 
  1   # ??
  
  julia&gt; x = 10^10^10^10^10  
  10  # I'd expect it to be 1? 1^10 == 1?
  
  julia&gt; x = 10^10^10^10^10^10 
  10000000000  # But here 10^10 == 10000000000, so now it works?
  
  
  julia&gt; typemax(Int64) &gt; 10^19
  true
  julia &gt; typemax(Int64) &gt; -10^19
  true
  </code></pre>
  <p>Can anyone shed light on the behaviour I am seeing?</p>
  <p><strong>EDIT:</strong></p>
  <p>Why does 9 overflow correctly, and 10 doesn't?</p>
  <pre><code>julia&gt; 9^(10^14)
  -1193713557845704703
  julia&gt; 9^(10^15)
  4900281449122627585
  julia&gt; 10^(10^2)
  0
  julia&gt; 10^(10^3)
  0
  </code></pre>
  <p>Julia 0.5.0 (2016-09-19)</p>