cmp() on integers - is there guarantee of returning only +-1 or 0?

Alex Martelli aleaxit at yahoo.com
Sun Mar 19 18:35:44 EST 2006


<skip at pobox.com> wrote:

>     def sign(n):
>         return n and n/abs(n) or 0
> 
> Whoops...  Make that
> 
>     def sign(n):
>         return n and n/abs(n) or 1

Uh?  I thought part of the specs was that sign(0) is 0...


Alex



More information about the Python-list mailing list