Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)]

Steven D'Aprano steve at pearwood.info
Thu Jul 21 12:10:18 EDT 2016


On Thu, 21 Jul 2016 11:14 pm, Rustom Mody wrote:

> On Thursday, July 21, 2016 at 12:04:35 PM UTC+5:30, Steven D'Aprano wrote:
>> On Thursday 21 July 2016 15:28, Rustom Mody wrote:
>> > BTW APL whose main domain of application is scientific chooses to
>> > enshrine this —equality is ε-neighborhood checking not exact equality
>> > checking — into its builtin ‘==’
>> 
>> I have a lot of respect for Ken Iverson, and a lot of admiration for
>> language designers willing to experiment with alternate paradigms.
> 
> This choice has significant(!!) costs: Fuzzy equality is not transitive:
> One can get
> a = b ∧ b = c ∧ a ≠ c
>> 
>> But keeping in mind that in APL, if you set ⎕ct to 0 you get an exact
>> comparison, can you find any quotes from Iverson saying that you should
>> *never* perform exact equality comparisons?
> 
> There you go with your strawmen!
> Remember it was you (and Chris) who expressed extreme positions:
> “Pernicious myth” “FUD” etc


And YOU'RE the one who is raising APL as an argument *against* my
characterisation.

Do you think that Iverson would agree with the conventional wisdom that we
should NEVER test floats for exact equality?

Do you know of ANY expert in numeric computation who will agree with the
conventional wisdom? If so, who?

I'll admit that I've stolen my description of this rule as "superstition"
from perhaps the world's foremost authority on numeric computation,
Professor William Kahan. (See the forward to "Apple Numerics Manual, Second
Edition, 1988.) You don't like my use of the term "pernicious"? In my
opinion, any conventional wisdom which keeps people *more* rather than
*less* ignorant is pernicious. Anything which discourages them from testing
their numeric functions to the full precision possible is pernicious.
Anything which encourages the idea that numeric computation using floats is
non-deterministic is pernicious.

But if you don't agree, feel free to dismiss the word as mere hyperbola and
MOVE ON. You don't have to nit pick about every word I use.

The bottom line is, while it is often true that using exact equality is
going to surprise people, the conventional wisdom to NEVER do so is both
(1) factually wrong, there are plenty of examples where one can and should
use exact equality, and (2) rather useless, as the conventional wisdom
gives no clue as to the practicalities of what to replace it with.




-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list