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

Christian Heimes lists@cheimes...
Tue Sep 29 15:53:52 CDT 2009


Christopher Barker wrote:
> Hi folks,
> 
> This isn't really a numpy question, and I'm doing this with regular old 
> python, but I figure you are the folks that would know this:
> 
> How do I get python to make a distinction between -0.0 and 0.0? IN this 
> case, I'm starting with user input, so:

How about using atan2()? :)

>>> from math import atan2
>>> atan2(-0., -1.)
-3.1415926535897931
>>> atan2(0., -1.)
3.1415926535897931


from math import atan2
def sign(x):
    if x > 0.:
        return +1
    if x < 0.:
        return -1
    # x == 0. or -0.
    if atan2(x, -1.) > 0:
        return +1
    else:
        return -1



More information about the NumPy-Discussion mailing list