[Numpy-discussion] making the distinction between -0.0 and 0.0..
Bruce Southey
bsouthey@gmail....
Tue Sep 29 12:17:34 CDT 2009
On 09/29/2009 12:08 PM, Gökhan Sever wrote:
>
>
> On Tue, Sep 29, 2009 at 11:53 AM, Christopher Barker
> <Chris.Barker@noaa.gov <mailto:Chris.Barker@noaa.gov>> 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:
>
> In [3]: float("-0.0")
> Out[3]: -0.0
>
> so python seems to preserve the "-". But:
>
> In [12]: float("-0.0") == float("0.0")
> Out[12]: True
>
> In [13]: float("-0.0") < float("0.0")
> Out[13]: False
>
> In [14]: float("0.0") > float("-0.0")
> Out[14]: False
>
> It doesn't seem to make the distinction between -0.0 and 0.0 in any of
> the comparisons. How can I identify -0.0?
>
> NOTE: numpy behaves the same way, which I think it should, but
> still...
>
> My back-up plan is to process the string first, looking for the minus
> sign, but that will require more changes than I'd like to the rest
> of my
> code...
>
> thanks,
> -Chris
>
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chris.Barker@noaa.gov <mailto:Chris.Barker@noaa.gov>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org <mailto:NumPy-Discussion@scipy.org>
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> No help from the decimal module. Although its documentation
> (http://docs.python.org/library/decimal.html) says:
>
> /A decimal number is immutable. It has a sign, coefficient digits, and
> an exponent. To preserve significance, the coefficient digits do not
> truncate trailing zeros. Decimals also include special values such as
> Infinity, -Infinity, and NaN. The standard also differentiates -0 from
> +0./
>
> When I try:
>
> from decimal import *
> a = Decimal('+0.0')
> b = Decimal('-0.0')
>
> a == b
> True
>
> No help for you either I guess :)
>
> --
> Gökhan
> ------------------------------------------------------------------------
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
Numpy support IEEE floating point standard so you have definitions for
negative zero (numpy.NZERO) and positive zero (numpy.PZERO):
http://docs.scipy.org/numpy/docs/numpy.NZERO/
http://docs.scipy.org/numpy/docs/numpy.PZERO/
Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090929/5309802c/attachment.html
More information about the NumPy-Discussion
mailing list