unittest: Proposal to add failUnlessNear
Antoon Pardon
apardon at vub.ac.be
Thu Jul 22 13:58:12 EDT 2004
John Roth <newsgroups at jhrothjr.com> wrote:
> "Christopher T King" <squirrel at WPI.EDU> wrote in message
> news:Pine.LNX.4.44.0407210901230.9717-100000 at ccc8.wpi.edu...
> > On Tue, 20 Jul 2004, John Roth wrote:
> >
> > > In addition, you're going to have to do significant
> > > type checking if you want to combine floats and
> > > complex in the same method call. That's just
> > > poor design.
> >
> > Why would you have to do that? The Python operators, as well as every
> > function in cmath, transparently support both floats and complex numbers
> > (as they should). Every operation between floats and complex numbers is
> > well-defined.
> Because the "distance" between two floats is
> abs(a - b)
> while the "distance" between two complex numbers
> is something like
is just the same: abs(a - b) it works for complex numbers
just as well as it does with floats. In fact it works for
any numberlike object that has __sub__ and __abs__ methods
defined.
> math.sqrt(diff.real ** 2 + diff.imag ** 2)
This is just the definition for abs on complex numbers.
> This requires a type check to differentiate which
> formula you need to use.
No it doesn't.
--
Antoon Pardon
More information about the Python-list
mailing list