[ python-Bugs-1118729 ] Error in representation of complex numbers(again)

SourceForge.net noreply at sourceforge.net
Fri Sep 16 07:02:45 CEST 2005


Bugs item #1118729, was opened at 2005-02-09 01:26
Message generated for change (Comment added) made by quiver
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1118729&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: George Yoshida (quiver)
Assigned to: Martin v. Löwis (loewis)
Summary: Error in representation of complex numbers(again)

Initial Comment:
>>> -(1+0j)
(-1+-0j)

I encountered this while I was calculating conjugate of 
complex numbers(e.g. z.conjugate()).

Related bug
* http://www.python.org/sf/1013908

One thing to note is that -(0j) can return 0j or -0j 
dependeing on OSes.

Confirmed on SuSE 9.1 & cygwin.

----------------------------------------------------------------------

>Comment By: George Yoshida (quiver)
Date: 2005-09-16 14:02

Message:
Logged In: YES 
user_id=671362

Can anyone else review this patch before the new 2.4 gets 
released?
The patch is ready to be commited.

----------------------------------------------------------------------

Comment By: George Yoshida (quiver)
Date: 2005-05-15 21:22

Message:
Logged In: YES 
user_id=671362

The fix seems reasonable to me and it passed the test 
suites. 

Please apply it.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2005-05-15 16:57

Message:
Logged In: YES 
user_id=21627

What do you think about the patch attached?

----------------------------------------------------------------------

Comment By: George Yoshida (quiver)
Date: 2005-03-20 02:11

Message:
Logged In: YES 
user_id=671362

Martin, what's your take on this?

The representation of '-(1+0j)' has changed since Revision 2.71
(complexobject.c) and you applied the patch.

# original patch
making Python LC_NUMERIC agnostic
  http://www.python.org/sf/774665

----------------------------------------------------------------------

Comment By: George Yoshida (quiver)
Date: 2005-02-10 09:02

Message:
Logged In: YES 
user_id=671362

Hi, Björn.

Sorry, not to be clear about what my complaint is.  I'm not 
talking about if -(0j) should be 0j or -0j.  It's been that way 
for a long time, so changing it would break old codes.

My point is the signature of imaginary part. As you can see, 
it's represented as '+-'. Before the commit of patch #774665, 
it was represented as '-1-0j'. But after that, '-1+-0j'.

If you test it with Python <= 2.3, you'll get (-1-0j) and I think 
this is how -(1+0j) should be represented on machines where -
(0j) is represented as -0j.


----------------------------------------------------------------------

Comment By: Björn Lindqvist (sonderblade)
Date: 2005-02-10 03:54

Message:
Logged In: YES 
user_id=51702

What you are seeing is negative zero (-0.0). It is distinct 
from positive zero (0.0) but 0.0 == -0.0 is always true. On 
some machines you can also see it by typing:

>>> -0.0
-0.0

On other machines you will see "0.0" instead. You can also try 
printf("%f\n", -0.0); and you will notice the same thing. So 
I'm not sure it is a bug per se. However, it can be worked 
around by adding "if (v->cval.imag == 0.) v->cval.imag = 
0.0;" to complexobject.c, assuming ofcourse it is OK to 
change negative zeros to positive ones.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1118729&group_id=5470


More information about the Python-bugs-list mailing list