3.0.2 release (mingw32 check)

John W. Eaton jwe at bevo.che.wisc.edu
Tue Aug 26 13:21:13 CDT 2008


On 26-Aug-2008, Benjamin Lindner wrote:

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

Because there is no special case for unary minus in the parser.  It is
still an expression that must be evaluated.

If we change that, then you would see different results for

  -i  ->  0 - 1i

and

  a = i; -a;  ->  -0 - 1i

Is that really what you want?

| Seems as "-i" is b
| imterpreted as "(-1)*i" whereas "-1/3" is a single expression. Right?

I'm not sure what you mean by "single expression".  They are both
expressions that must be evaluated.  The expression -i is parsed as

  unary-minus imaginary-constant

and the expression -1/3 is parsed as

 unary-minus constant / constant

with the unary-minus having higher precedence than the division
operation.  In lisp notation, these would be

 (- I)
 (/ (- 1.0) 3.0)

(assuming I is the complex constant with real part 0 and imaginary
part 1).

jwe


More information about the Octave-maintainers mailing list