3.0.2 release (mingw32 check)
Benjamin Lindner
lindnerben at gmx.net
Tue Aug 26 11:35:11 CDT 2008
John W. Eaton wrote:
> On 26-Aug-2008, Benjamin Lindner wrote:
>
> | I assumed it, because the output is printed as a complex number:
> |
> | octave:1> mat2str([-1/3])
> | ans = -0.33333333333333331
> | octave:2> mat2str([-1/3,i])
> | ans = [-0.33333333333333331+0i;0+1i]
> |
> | In the second case, -1/3 is printed as a complex number, thus I assumed
> | it must be expanded. I guess [-1/3,i] is internally stored as a complex
> | 2x1 matrix, so every element is "expanded" to a complex number. "expand"
> | might be the wrong terminus here, "convert" would be more appropriate,
> | sorry.
>
> I thought you were talking about -1/3 by itself, not in the context of
> [-1/3, i]. In that case, Octave initially reads a list of
> epxressions. Then when evaluating the [] operator expression to
> create a matrix, each element is evaluated in turn. -1/3 is purely
> real. i is complex. When combining the elements to make the overall
> matrix, Octave notes that some elements are complex and produces a
> complex matrix. When converting reals to complex, it calls the
> std::complex constructor to create the complex value. That
> constructor sets the imaginary part to zero regardless of whether the
> real part is negative. I think that is a reasonable choice.
Thanks for the insight, I believe I see now why octave behaves the way
it behaves...
So -1/3 being converted into a complex number yields -1/3+0i because of
the std::complex constructor setting the imag part by default to zero.
Whereas -i is created as std::complex with real part zero and then
negated, which yields a real part of -0.
Now out of curiosity:
Why is the expression "-i" not immediatly created as std::complex with a
imaginary part of -1 and a default real part of 0? Seems as "-i" is
imterpreted as "(-1)*i" whereas "-1/3" is a single expression. Right?
>
> The real problem is that we have no pure imaginary values, so i is
> stored as (0,1).
> I don't think the complex number negation operator
> should have a special case for when the real part is zero, do you?
>
No, I don't see a necessity here. Makes things only more complicated,
with no real benefit.
benjamin
More information about the Octave-maintainers
mailing list