[PYTHON MATRIX-SIG] floating point equalities

Hinsen Konrad hinsenk@ere.umontreal.ca
Tue, 23 Jan 1996 15:29:31 -0500


   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

Are you sure that you have installed the latest version of my complex
object? It should give 1j**2 == -1., exactly.  The reason is that
complex_power() detects that the exponent is actually an integer (no
fractional or imaginary part), and then calls c_powi(), which in turn
calls c_powu() because the exponent is positive and less than
100. c_powu() reduces the power calculation to an optimized sequence
of multiplications. Therefore 1j**2 is exactly equivalent to
1j*1j. (And yes, I have traced this example with a debugger right now
because I was a bit worried).

What does 1j*1j give on your system? It ought to be exactly -1., since
there are no round-off errors in this calculation.

I realize that this has nothing to do with doing comparisons in
general, of course...

-------------------------------------------------------------------------------
Konrad Hinsen                     | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie             | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal            | Fax:  +1-514-343-7586
C.P. 6128, succ. Centre-Ville     | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7             | Francais (phase experimentale)
-------------------------------------------------------------------------------

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

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