[Python-Dev] Floor division

Alexey Borzenkov snaury at gmail.com
Wed Jan 24 11:20:42 CET 2007


On 1/24/07, Gareth McCaughan <gareth.mccaughan at pobox.com> wrote:

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


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:

  *complex*( [real[, imag]]) Create a complex number with the value *real +
imag*j* or convert a string or number to a complex number. If the first
parameter is a string, it will be interpreted as a complex number and the
function must be called without a second parameter. The second parameter can
never be a string. Each argument may be *any numeric type* (*including
complex*). If imag is omitted, it defaults to zero and the function serves
as a numeric conversion function like int(), long() and float(). If both
arguments are omitted, returns 0j.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20070124/4e5e6fd2/attachment.htm 


More information about the Python-Dev mailing list