title: Why is this long overflowing to -1, instead of the minimum value for the type?
body: <p>I have the following code that returns the number of nodes in a tree when a complete Binary Tree is <code>layer</code> layers tall:</p>
  
  <pre><code>public static long nNodesUpToLayer(int layer) {
          if (layer &lt; 0) throw new IllegalArgumentException(
              "The layer number must be positive: " + layer );
  
          //At layer 0, there must be 1 node; the root.
          if (layer == 0) return 1;
  
          //Else, there will be 1 + 2 * (the number of nodes in the previous layer) nodes.
          return 1 + (2 * nNodesUpToLayer(layer - 1));
  </code></pre>
  
  <p>The odd thing is, when I input <code>63</code> into the function (the minimum value that produces this), it gives me back <code>-1</code>. At <code>62</code>, it gives back <code>9223372036854775807</code>, so this seems to be caused by an overflow.</p>
  
  <p>Shouldn't it give me back the minimum value of Java's long + the amount that it was overflowed by? Regardless of the input that I give it though (passed <code>62</code>), it will always return <code>-1</code> instead of a seemingly random number that I'd expect from an overflow.</p>
  
  <p>I'm not entirely sure how to debug this, since it's recursive, and the value I'm interested in will only be evaluated once the the function has reached the base-case.</p>