no sign() function ?

Stephen Thorne stephen at thorne.id.au
Mon Dec 22 13:20:58 CET 2008


On 2008-12-22, Pierre-Alain Dorange wrote:
> def sign(x):
>     if x==0.0:
>         return 0.0
>     elif x>0.0:
>         return 1.0
>     else:
>         return -1.0

Isn't this approximately this? ::

    def sign(x):
        return float(cmp(x, 0))

Or if you don't want a float response::

    def sign(x):
        return cmp(x, 0)

-- 
Regards,
Stephen Thorne
Development Engineer
NetBox Blue - 1300 737 060



More information about the Python-list mailing list