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.
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?