[Python-Dev] Floor division

Gareth McCaughan gareth.mccaughan at pobox.com
Wed Jan 24 10:00:04 CET 2007


On Wednesday 24 January 2007 08:39, Alexey Borzenkov wrote:

[me, about complex():]
> > It seems pretty clear what it thinks it's doing -- namely,
> > defining complex(a,b) = a + ib even when a,b are complex.
> > And half of why it does that is clear: you want complex(a)=a
> > when a is complex. Why b should be allowed to be complex too,
> > though, it's hard to imagine.

[Alexey:]
> I think that's the right thing to do, because that is mathematically
> correct. j is just an imaginary number with a property that j*j = -1. So
> (a+bj) + (c+dj)j = (a-d) + (b+c)j.

Yes, thanks, I know what j is, and I know how to multiply
complex numbers. (All of which you could have deduced from
reading what I wrote, as it happens.) The question is whether
it makes sense to define complex(a,b) = a+ib for all a,b
or whether the two-argument form is always in practice going
to be used with real numbers[1]. If it is, which seems pretty
plausible to me, then changing complex() to complain when
passed two complex numbers would (1) notify users sooner
when they have errors in their programs, (2) simplify the
code, and (3) avoid the arguably broken behaviour Tim was
remarking on, where complex(-0.0).real is +0 instead of -0.

    [1] For the avoidance of ambiguity: "real" is not
        synonymous with "double-precision floating-point".

>                                    Complex numbers are not just magic 
> pairs with two numbers and have actual mathematical rules.

Gosh, and there I was thinking that complex numbers were magic
pairs where you just make stuff up at random. Silly me.

-- 
Gareth McCaughan
PhD in pure mathematics, University of Cambridge


More information about the Python-Dev mailing list