title: What's the most efficient way to test if two ranges overlap?
body: <p>Given two inclusive ranges [x1:x2] and [y1:y2], where <code>x1 ≤ x2</code> and <code>y1 ≤ y2</code>, what is the most efficient way to test whether there is any overlap of the two ranges?</p>
  <p>A simple implementation is as follows:</p>
  <pre><code>bool testOverlap(int x1, int x2, int y1, int y2) {
    return (x1 &gt;= y1 &amp;&amp; x1 &lt;= y2) ||
           (x2 &gt;= y1 &amp;&amp; x2 &lt;= y2) ||
           (y1 &gt;= x1 &amp;&amp; y1 &lt;= x2) ||
           (y2 &gt;= x1 &amp;&amp; y2 &lt;= x2);
  }
  </code></pre>
  <p>But I expect there are more efficient ways to compute this.</p>
  <p>What method would be the most efficient in terms of fewest operations?</p>