Emil Jerabek wrote:
(I'm surprised a bit that nobody noticed this before.)
Me too. #-(
The complex "pow" operator gives completely bogus results with negative exponents. Example:
[artax:pascal]% cat tst.pas program Foo (Output);
var z: Complex;
begin z := Cmplx (5, 0) pow (-1); WriteLn (Re (z) : 5 : 1, Im (z) : 5 : 1) end. [artax:pascal]% gpc tst.pas [artax:pascal]% ./a.out 1.0 0.0
The "Complex_Pow" function in rts/math.pas computes reciprocals as 1 / (x+iy) := (x-iy) / |x+iy|, which is a nonsense.
Yes, should have been | |^2, of course.
Here is a patch (recycling a Maurice's idea to make it work for too big or too small arguments).
Thanks, I'll aply it. (emil8.pas)
BTW, are there any serious reasons why the complex "**" operator accepts only _real_ exponents?
ISO 10206 defines it only for integer and real exponents. I also doubt how usual this notation is in mathematics. (Of course, it can be defined just like for reals, but ARAIR some theorems known from the real power function don't hold in the complex case.)
As far as the RTS is concerned, it would suffice to change "Double" to "Complex" in the declaration of "Complex_Power", but I expect that it needs some compiler magic as well.
Yes, but if we'd really do it, we should probably provide two versions, so the case of real exponents won't be less efficient when it's done in complex.
Frank