[Python-ideas] Way to check for floating point "closeness"?

Andrew Barnert abarnert at yahoo.com
Tue Jan 13 01:26:05 CET 2015


On Jan 12, 2015, at 15:51, Devin Jeanpierre <jeanpierreda at gmail.com> wrote:

> On Mon, Jan 12, 2015 at 3:48 PM, Devin Jeanpierre
> <jeanpierreda at gmail.com> wrote:
>> On Mon, Jan 12, 2015 at 3:34 PM, Chris Barker <chris.barker at noaa.gov> wrote:
>>> And I hate to bring this up, but any reason for a cmath.nan and cmath.inf ?
>> 
>> One constant would be weird. cmath has more than one or two infinitely
>> far away points, it has eight. (Maybe nan is more obviously nan+nanj
>> though.)

Well, something like nan+1j or 1+nanj is also sort of nan (as cmath.isnan reflects; also, operations like addition or conjugate that treat real and imag separately properly preserve the nanness or numberness of each part, but those that have to combine them like multiplication convert both to nan). In fact, complex(float('nan')) is nan+0j, not nan+nanj. I don't know if that argues for or against having a cmath.nan.

But I think the unavoidable ambiguity of cmath.inf argues against having cmath.nan.

> Er, it has infinitely many, of course. I didn't think that through. :)

Nah, only 4 * the perfectly finite number of float values. :)


More information about the Python-ideas mailing list