unittest: Proposal to add failUnlessNear

Tim Peters tim.peters at gmail.com
Wed Jul 21 21:19:21 EDT 2004


[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().



More information about the Python-list mailing list