octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About -0 and type complex


From: Daniel J Sebald
Subject: Re: About -0 and type complex
Date: Tue, 09 Oct 2012 12:41:59 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 10/09/2012 12:22 PM, Michael D. Godfrey wrote:
I would just like to ask if the following behavior seems right
to you. And, is there a way to set the imaginary part of
a complex to -0?

octave:46> -(1-1)
ans = -0
octave:47> -(1-1) +0i
ans = 0
octave:48> -(1-1) -0i
ans = -0
==================
The obvious question is: why does the sign of the imaginary
part change the sign of the real part?

Well, what you've written isn't manipulating the real/imaginary part, from what I gathered of the discussion about a month back related to this. The commands above are adding two different numbers and how the addition rules act might be slightly different than what you have in mind, which is

octave-cli:7> real(complex(-0,0))
ans = -0
octave-cli:8> real(complex(0,0))
ans = 0
octave-cli:9> real(complex(-0,0))
ans = -0
octave-cli:10> real(complex(0,-0))
ans = 0
octave-cli:11> real(complex(-0,-0))
ans = -0

Let's try some of the calculations you wrote:

octave-cli:12> x = -(1-1)
x = -0
[I think that was 1-1 is 0 and minus 0 is -0]
octave-cli:13> x = -(1-1) + complex(0,0)
x = 0
[I think that was -0 + 0 which is probably 0]
octave-cli:14> x = -(1-1) + complex(0,-0)
x = 0
[I think that was -0 + 0 again, which is 0]
octave-cli:15> x = -(1-1) - 0i
x = -0
[I think that was -0 - 0, which is -0]
octave-cli:16> x = -(1-1) - complex(0,0)
x = -0
[Same as the last case, the sign of the complex portion not having any significance.]

Dan


 The math definitions for
arg(z) and |z| treat the real and imaginary parts symmetrically.

I have not found a standard for +-0 for complex, but it would
seem reasonable to treat the real and imaginary parts according
to the same rule. And, is it a good idea to reduce a complex
with +-0 imaginary part to real? Saves space, I know, but the
sign is lost.

Currently, for complex the rule is:
real imag result
-0 -0 -0
-0 0 0
0 -0 0

In effect, there is no -0 imaginary part even though -0i affects
results.

I know that this seems pretty academic, but it is getting in the way
of my figuring out the correct corner values of atan2(y,x) for complex
arguments (another pretty academic pursuit. I know).

If you think this is good enough, I will just add it to the documentation
about -0. At least, users should know what is supposed to happen.

Michael


--

Dan Sebald
email: daniel(DOT)sebald(AT)ieee(DOT)org
URL: http://www(DOT)dansebald(DOT)com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]