Negative integers

nntpman68 news1234 at
Thu Aug 21 00:15:52 CEST 2008


Dan's solution is probably the clearest.

Just out of curiousity:.

How would you in your program's context like 0 to be treated.

should it be treated as a positive number or should it be treated as
a case part.

my suggestion a*b > 0 for example
wouldn't work if you want 0 to be treated as positive number or if you
compare 0 with 0 and want 'same sign' as answer



johnewing 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

More information about the Python-list mailing list