[Python-Dev] Floor division (original) (raw)

Gareth McCaughan gareth.mccaughan at pobox.com
Wed Jan 24 12:22:09 CET 2007


On Wednesday 24 January 2007 10:20, Alexey Borzenkov wrote:

> > 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.

Haven't looked in source code for complex constructor yet, but I think that if it changes sign of -0.0 then it just does something wrong and needs fixing without change in behaviour. Maybe it could check if numbers it got on input are real or complex and proceed accordingly so that it never gets to computing -0.0-(+0.0), i.e. when second argument is not a complex number it could just add it to imaginary part of first argument, but skip substracting inexistant 0.0 from first argument's real part. Change of behaviour like ignoring imaginary part of second argument seems bad to me, and that's my only point. Besides, documentation (at least for Python 2.4) clearly states that second argument can be a complex number:

I'm not suggesting that it should ignore the imaginary part of the second argument, and I don't think anyone else is either. What might make sense is for passing a complex second argument to raise an exception.

(I don't particularly object to the present behaviour either.)

The fact that the documentation states explicitly that the second argument can be a complex number is probably sufficient reason for not changing the behaviour, at least before 3.0.

-- g



More information about the Python-Dev mailing list