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

Neil Girdhar mistersheik at gmail.com
Wed May 13 08:24:04 CEST 2015


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

Best,

Neil


On Tuesday, May 12, 2015 at 3:18:47 AM UTC-4, Mark Summerfield wrote:
>
> From Python 3.2 it is easy to compare floats, e.g.,
>
> 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).
>
> 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?)
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150512/2537d9dd/attachment.html>


More information about the Python-ideas mailing list