no sign() function ?

Arnaud Delobelle arnodel at googlemail.com
Tue Dec 23 09:46:59 CET 2008


pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) writes:

> def sign_0(x):
>         if x==0.0:
>                 return 0.0
>         elif x>0.0:
>                 return 1.0
>         else:
>                 return -1.0
>  

This might be slightly faster:

def sign(x):
    return 1 if x > 0 else x and -1

-- 
Arnaud



More information about the Python-list mailing list