[Python-ideas] Fwd: Add math.iszero() and math.isequal()?

Chris Barker chris.barker at noaa.gov
Thu May 14 22:37:00 CEST 2015


something went weird with the google groups mirror of this list -- sorry if
this lands twice.

-Chris

---------- Forwarded message ----------
From: Chris Barker <chris.barker at noaa.gov>
Date: Thu, May 14, 2015 at 1:34 PM
Subject: Re: [Python-ideas] Add math.iszero() and math.isequal()?
To: Neil Girdhar <mistersheik at gmail.com>
Cc: "python-ideas at googlegroups.com" <python-ideas at googlegroups.com>




On Tue, May 12, 2015 at 11:24 PM, Neil Girdhar <mistersheik at gmail.com>
wrote:

> See PEP 485, which appears to be still a draft:
> https://www.python.org/dev/peps/pep-0485/
>

It's been approved, and it's "just" waiting for me to implement the code
and get it reviewed, etc.

I've been much sidetracked, but hoping to get to in the next couple days....

iszero = lambda x: hash(x) == hash(0)
>> isequal = lambda a, b: hash(a) == hash(b)
>>
>> Clearly these are trivial functions (but perphaps math experts could
>> provide better implementations; I'm not proposing the implementations
>> shown, just the functions however they are implemented).
>>
>
I'm not familiar with how hashing works for floats, but I can't image this
would even work -- == an !== work for floats, then just don't test what
people most often want :-)

Anyway, see the PEP, and the quite long and drawn out discussion on this
list a couple months back.

-CHB






>
>> It seems that not everyone is aware of the issues regarding comparing
>> floats for equality and so I still see code that compares floats using ==
>> or !=.
>>
>> If these functions were in the math module it would be convenient (since
>> I find I need them in most non-trivial programs), but also provide a place
>> to document that they should be used rather than == or != for floats. (I
>> guess a similar argument might apply to the cmath module?)
>>
>>
>>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 

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 at noaa.gov



-- 

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 at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150514/07018675/attachment.html>


More information about the Python-ideas mailing list