title: Detect signed int overflow in Go
body: <p>I'm building a Lisp, and I want 32 bit integers to automatically switch to 64 bit integers if a computation would cause them to otherwise overflow. And likewise, for 64 bit overflows, switch to arbitrarily sized integers.</p>
  
  <p>The problem I have is that I don't know what the "correct" way is to detect an integer overflow.</p>
  
  <pre><code>a, b := 2147483647, 2147483647
  c := a + b
  </code></pre>
  
  <p>How can I efficiently check if c overflowed?</p>
  
  <p>I have considered always converting to 64 bit values to do the calculation, then down-sizing again afterwards when possible, but that seems expensive and memory wasteful for something that is as primitive and core to the language as basic arithmetic.</p>