in reply to Re: Re: Compare two signed integers without using comparision operator in perl
in thread Compare two signed integers without using comparision operator in perl
abs($a-$b) - ($a-$b) equals 0 when $a>=$b, and equals 2*abs($a-$b) when $a<$b.
Perhaps you meant to say abs($a-$b)/($a-$b). This would produce the same (-1,0,1) that <=> returns, but it needs special handling to avoid division by zero, e.g. the eval in tye's post.
|
|---|