in reply to Speeding up point-in-polygon -- take two

Unroll the condition and duplicate the process (or subroutine):

if ( $y[i] <= $y ) { if ( $y < $y[$j] ) { # process ... } } elsif ( $y >= $y[$j] ) { # the same process .. }
Or a simple calculation:
if ( ( $y[$i] - $y ) * ( $y - $y[$j] ) > 0 ) { # process
Remember: Memoize is your friend.