[PYTHON MATRIX-SIG] floating point equalities

Guido van Rossum guido@CNRI.Reston.VA.US
Tue, 23 Jan 1996 14:37:35 -0500


> I'd like to have a method approxEqual (or some similar name) so that
> a.approxEqual(b) will "do the right thing".  I had believed that there
> was some sort of consensus in the numerical programming community on
> what the right thing is for floating point numbers, if I'm wrong on
> this, I'd like to know that too.

Cool.

> Note: part of why this came up is the fact that on my development
> system (1j)**2 == (-1+1.22460635382e-16j).  I'd really like to be able
> to have some way to say approxEqual((1j)**2, -1) and have it come out
> true (OK, I have an ad hoc solution that works, what I want is the
> "right" solution if there is one out there).

I bet this is because in x**y, Python currently coerces y, meaning you
were really calculating 1.0j ** 2.0j...

(Note that the (by now pathetically incomplete) Python test suite has
a similar problem and solution when testing the pow() function.)

--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
=================