On Mon, 22 Dec 2008 12:31:44 +0100, Pierre-Alain Dorange wrote:

>> > I don't find any sign(x) function in the math library (return the
>> > sign of the value).
>> > I've read that math module is a wrapper to C math lib and that C math
>> > lib has not sign(), so...
[snip]
> As my need is for a game and that i do not have IEEE real concern, i
> would simply using my simple function (but not as accurate) :
> 
> def sign(x):
>     if x==0.0:
>         return 0.0
>     elif x>0.0:
>         return 1.0
>     else:
>         return -1.0

I found this snippet to be quite succinct (even though being smart 
*might* be wrong in programming)::

    sign = lambda x:+(x > 0) or -(x < 0)

HTH,

-- 
Robert "Stargaming" Lehmann
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to