[PYTHON MATRIX-SIG] floating point equalities

James Hugunin jjh@Goldilocks.LCS.MIT.EDU
Tue, 23 Jan 96 15:39:21 EST

   From: hinsenk@ere.umontreal.ca (Hinsen Konrad)

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

My fault, I'm still running with an old version of your patch.
I'll install the new one before I do much more testing.  (Still, this
problem comes up in many other places).


MATRIX-SIG  - SIG on Matrix Math for Python

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