Negative integers
Uwe Schmitt
rocksportrocker at googlemail.com
Thu Aug 21 04:54:14 EDT 2008
On 20 Aug., 23:38, johnewing <john.... at gmail.com> wrote:
> I am trying to figure out how to test if two numbers are of the same
> sign (both positive or both negative). I have tried
>
> abs(x) / x == abs(y) / y
>
> but that fails when one of the numbers is 0. I'm sure that there is
> an easy way to do this. Any suggestions?
>
> Thanks
Multiply with x and y and you get
abs(x) * y == abs(y) * x
which avoids zero division.
but testing x*y > 0 is easier.
Greetings, Uwe
More information about the Python-list
mailing list