[Python-ideas] Floating point "closeness" Proposal Outline

Joao S. O. Bueno jsbueno at python.org.br
Wed Jan 21 12:27:39 CET 2015


While we are at this, since someone will have to step up to come up with a PEP,
I have these two ideas to drop in the brainstorm - as I'd like to the
one writting the
PEP text to at least have them in mind:


1)  Implement a Number class that behaves as a float number, and does
the fuzzy comparisons automatically.

Justificative: in a whole lot of code, having a "casted"
FuzzyFloat(mynumber) to be able to be compared to others with "==" and "<="
would be much more readable than the Javaesque

" if is_close(my_number, other) or my_number < other: "
(against:
 "if FuzzyFloat(my_number) <= other :"
, or simply

"if my_number <= other: "

if we are already working with the FuzzyFloat type)

It could use a "context" just like "decimal" to specify
comparison parameters

I made a naive approach to this when these threads started a couple of
days ago -
of course it is far from a real implementation -

https://gist.github.com/jsbueno/1e62be882639a13180f6

(forgive me for not using ABC's there, I just wrote that to have a
"feel" on this idea
on the interactive console - and it was a nice test-drive)

2) Put a though on how things could work with other numeric types
than float and complex - "decimal" comes to mind.

  js
 -><-


More information about the Python-ideas mailing list