unittest: Proposal to add failUnlessNear

John Roth newsgroups at jhrothjr.com
Thu Jul 22 07:28:00 EDT 2004


"Tim Peters" <tim.peters at gmail.com> wrote in message
news:mailman.689.1090459164.5135.python-list at python.org...
> [Tim Peters]
> >> Nope.  abs(a - b) works for both cases, although for complex numbers
> >> Python uses a numerical method less prone to spurious
> >> overflow/underflow than the "square root of the sum of the squares"
> >> formula.
>
> [John Roth]
> > I didn't know that. It does make sense to do something like
> > that, but it seems a bit like deep magic to make abs
> > recognize that the operand is a subtraction.
>
> That would be deep magic indeed!  But that doesn't happen.  abs(x)
> works on "a number".  Regardless of whether a and b are float or
> complex or integer or a mix, abs(a-b) first subtracts b from a, then
> passes the difference to abs().

Is that how complex subtraction works? I thought it produced
a complex, and your answers seem to say it produces a real.
Obviously, my mathematical background isn't giving me the
same answers it's giving you.

John Roth





More information about the Python-list mailing list