Overlapping intervals

Checking if two intervals overlap is covered on this page:


which shows intervals

(s1, e1)
(s2, e2)

overlap if

(s2 < e1)∧(s1 < e2)

If the intervals are specified by a width

(s1, (s1 + w1))
(s2, (s2 + w2))

then the overlap test is

(s2 < (s1 + w1))∧(s1 < (s2 + w2))

The expression

a < (b + c)

is equivalent to evaluating

a − b − c

and checking that the result is negative by examining the sign bit.

So this expression is negative if the intervals overlap:

(s2 − s1 − w1)∨(s1 − s2 − w2)