Author mark.dickinson
Recipients mark.dickinson
Date 2007-11-27.22:25:11
SpamBayes Score 0.0162213
Marked as misclassified No
Message-id <1196202312.79.0.339731037994.issue1507@psf.upfronthosting.co.za>
In-reply-to
Content
In Python2.5 and the current trunk, construction of a complex number from two floats 
loses the negative sign of a negative zero in the imaginary part.

>>> complex(-0., 0.).real  # behaves as expected
-0.0
>>> complex(0., -0.).imag  # loses sign of zero
0.0

There are situations where it's important to preserve the sign of zero (typically 
when doing calculations involving functions with branch cuts);  there are probably 
platforms where this is difficult for one reason or another, but on a platform that 
complies with all the usual standards I can't see any reason for Python not to 
preserve the signs of zeros, provided that it's straightforward to do so.

The attached patch changes the complex constructor so that if x and y are numeric 
and neither x nor y is complex (or a subclass of complex) then complex(x, y) simply 
places x into the real part of the complex number and y into the imaginary part.  
For someone who doesn't care about the sign of zeros, this patch will have no 
noticeable effect.  Similarly, on a system that does not have full hardware or 
system support for signed zeros, this patch should be harmless.  Note that the patch 
does *not* change the feature that complex(z1, z2) returns z1 + 1j*z2 when z1 and/or 
z2 is itself complex.

There was some previous discussion of this on python-dev earlier this year.  See

http://mail.python.org/pipermail/python-dev/2007-January/070770.html
Files
File name Uploaded
complex_new.patch mark.dickinson, 2007-11-27.22:25:11
History
Date User Action Args
2007-11-27 22:25:12mark.dickinsonsetspambayes_score: 0.0162213 -> 0.0162213
recipients: + mark.dickinson
2007-11-27 22:25:12mark.dickinsonsetspambayes_score: 0.0162213 -> 0.0162213
messageid: <1196202312.79.0.339731037994.issue1507@psf.upfronthosting.co.za>
2007-11-27 22:25:12mark.dickinsonlinkissue1507 messages
2007-11-27 22:25:12mark.dickinsoncreate