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

Alex Martelli aleaxit at yahoo.com
Mon Mar 20 00:35:44 CET 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