note
ariels
Precedence is not the issue in comparing
<blockquote><code>
$x >= $x_min and $x <= $x_max and $y >= $y_min and $y <= $y_max
</code></blockquote>
with
<blockquote><code>
($x >= $x_min and $x <= $x_max) and ($y >= $y_min and $y <= $y_max)
</code></blockquote>
Neither will work if <tt>[and]</tt> has higher precedence than <tt>[<=]</tt> and <tt>[>=]</tt>!
<p>
The issue with the extra brackets here is to add a structure to the code that simplifies understanding. Instead of having to understand 4 independent logical tests, I have to understand 2 logical tests, then combine them. And once I've worked out the first test is "<tt>$x</tt> is between <tt>$x_min</tt> and <tt>$x_max</tt>", the second test is much easier to work out.
<p>
An alternative way to produce the division is simply by using a line break:
<blockquote><code>
$x >= $x_min and $x <= $x_max and
$y >= $y_min and $y <= $y_max
</code></blockquote>
also makes the analogy easier.
<p>
In any case, a much nicer way to write an interval test (if you're worried about readability) is to put <tt>$x</tt> on the inside, and keep all comparisons using the same direction:
<blockquote><code>
$x_min <= $x and $x <= $x_max and
$y_min <= $y and $y <= $y_max
</code></blockquote>
98810
98817