unittest: Proposal to add failUnlessNear
Roy Smith
roy at panix.com
Thu Jul 22 08:29:02 EDT 2004
"John Roth" <newsgroups at jhrothjr.com> wrote:
> Because the "distance" between two floats is
>
> abs(a - b)
>
> while the "distance" between two complex numbers
>
> is something like
>
> math.sqrt(diff.real ** 2 + diff.imag ** 2)
The distance between two complex numbers is indeed computed using the
pythagorean formula, but all that is hidden from view when you just say
"abs (a - b)".
>>> import math
>>> a = 1 + 3j
>>> b = -3 + 1j
>>> math.sqrt ((a.real - b.real) ** 2 + (a.imag - b.imag) ** 2)
4.4721359549995796
>>> abs (a-b)
4.4721359549995796
More information about the Python-list
mailing list