[PYTHON MATRIX-SIG] floating point equalities

Guido van Rossum guido@CNRI.Reston.VA.US
Tue, 23 Jan 1996 13:26:24 -0500


> I'm now working on improving the floating point equality operator.  My
> understanding is that doing a == b is unreasonable for floating point
> numbers, and instead the test should be something like 
> 
> abs(a-b) < TOLERANCE*abs(a)

Hm.  If you put this in the array module it would be a reasonable
expectation that it would also work for ordinary Python floats, which
it doesn't.  Also, the tolerance may be application dependent or
dependent on the part of the application that's doing this, so it may
need to be specified in the operation.

I'd advise to continue using C's '==' operator for floats (which is
what ordinary Python floats do).  Users who know enough to write
numerical code should also know not to compare for equality.

(What you could do is provide a method or function for comparisons
where you can pass the tolerance in as an argument.)

--Guido van Rossum <guido@CNRI.Reston.VA.US>
URL: <http://www.python.org/~guido/>

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================