[Numpy-discussion] making the distinction between -0.0 and 0.0..

Xavier Saint-Mleux saintmlx@apstat....
Tue Sep 29 12:40:56 CDT 2009


Christopher Barker wrote:
> Pauli Virtanen wrote:
>   
>> Tue, 29 Sep 2009 09:53:40 -0700, Christopher Barker wrote:
>> [clip]
>>     
>>> How can I identify -0.0?
>>>       
>> signbit
>>
>>     
>
> perfect for numpy, but at this point I don't have a numpy dependency 
> (very unusual for my code!). Anyone know a pure-python way to get it?
>   

Starting with Python 2.6, there is a copysign function in the math module:

>>> import math
>>> math.copysign(1, -0.)
-1.0
>>> math.copysign(1, 0.)
1.0

http://docs.python.org/library/math.html

HTH,


Xavier




More information about the NumPy-Discussion mailing list