Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8894519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:31:14+00:00 2026-06-14T23:31:14+00:00

I am wondering about the way Python (3.3.0) prints complex numbers. I am looking

  • 0

I am wondering about the way Python (3.3.0) prints complex numbers. I am looking for an explanation, not a way to change the print.

Example:

>>> complex(1,1)-complex(1,1)
0j

Why doesn’t it just print “0”? My guess is: to keep the output of type complex.

Next example:

>>> complex(0,1)*-1
(-0-1j)

Well, a simple “-1j” or “(-1j)” would have done. And why “-0”?? Isn’t that the same as +0? It doesn’t seem to be a rounding problem:

>>> (complex(0,1)*-1).real == 0.0
True

And when the imaginary part gets positive, the -0 vanishes:

>>> complex(0,1)
1j
>>> complex(0,1)*-1
(-0-1j)
>>> complex(0,1)*-1*-1
1j

Yet another example:

>>> complex(0,1)*complex(0,1)*-1
(1-0j)
>>> complex(0,1)*complex(0,1)*-1*-1
(-1+0j)
>>> (complex(0,1)*complex(0,1)*-1).imag
-0.0

Am I missing something here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:31:16+00:00Added an answer on June 14, 2026 at 11:31 pm

    It prints 0j to indicate that it’s still a complex value. You can also type it back in that way:

    >>> 0j
    0j
    

    The rest is probably the result of the magic of IEEE 754 floating point representation, which makes a distinction between 0 and -0, the so-called signed zero. Basically, there’s a single bit that says whether the number is positive or negative, regardless of whether the number happens to be zero. This explains why 1j * -1 gives something with a negative zero real part: the positive zero got multiplied by -1.

    -0 is required by the standard to compare equal to +0, which explains why (1j * -1).real == 0.0 still holds.

    The reason that Python still decides to print the -0, is that in the complex world these make a difference for branch cuts, for instance in the phase function:

    >>> phase(complex(-1.0, 0.0))
    3.141592653589793
    >>> phase(complex(-1.0, -0.0))
    -3.141592653589793
    

    This is about the imaginary part, not the real part, but it’s easy to imagine situations where the sign of the real part would make a similar difference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there was any decent way, other than NSLog-ing just about
Just wondering about the performance impact of copying very large php variables. For example
I'm wondering about the preferred way to import packages in a Python application. I
I'm currently teaching myself Python and was just wondering (In reference to my example
I'm wondering if there is a way to get better information about the location
I was wondering what is the best way to go about comparing a pixel
I am wondering if this is the best way to go about solving my
Just wondering about this code below... when I turn off my internet connection and
Just wondering about some practice about this; I have made a simple visual C#
wondering about the best way to approach this particular problem and if any libraries

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.