History of `isapprox` in languages

You are trying to grapple with the question of how to compare floating-point numbers, hoping that there a cure for “isapprox”. Lots of responses.
Here’s mine.
Don’t use it.
That is, Google will find admonitions: Don’t compare floating point numbers for equality. “near equality” doesn’t make it easier.

Consider if what you intend by a particular use of isapprox(a,b) is
-eps +a < b < eps+a or
equivalently abs(a-b)<eps
where eps can be scaled,say by max(abs(a), abs(b),machine-epsilon) … or some other factor, depending on what you actually need. Defining to do it
“for all cases” by isapprox() is implausible.

There are situations in which particular aspects of floating-point
representation are examined by bit-twiddling subroutine libraries
involving machine epsilon, Not-A-Number, extended precision, etc.
Testing for exact or nearly corresponding bit patterns might have
a use in such software, but typically done by experts in floating-point
error analysis. There aren’t too many around in the community of language designers.
Richard Fateman, UC Berkeley

11 Likes