in reply to Seeing if two numbers have the same sign
You are doing more work than you need to. Remember that mathematical comparisons return booleans, and booleans can be directly compared.
if ($x<0 == $y<0) { print "$x and $y have the same sign"; }
(($x ^ $y) < 0) would probably also work assuming they are integers. I think the trick with abs or the comparison operator would probably actually be less efficient than doing a comparison. Using multiplication is going to be slow as well.
BTW the sign of zero isnt a theological debate, it is an implementation detail of the machine you are working on and the data types you are using. :-)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Seeing if two numbers have the same sign
by WoodyWeaver (Monk) on Jan 10, 2008 at 23:18 UTC | |
by demerphq (Chancellor) on Jan 11, 2008 at 19:23 UTC | |
Re^2: Seeing if two numbers have the same sign
by hipowls (Curate) on Jan 10, 2008 at 21:22 UTC | |
by graff (Chancellor) on Jan 12, 2008 at 17:48 UTC | |
Re^2: Seeing if two numbers have the same sign
by girarde (Hermit) on Jan 11, 2008 at 18:00 UTC |