Emil Jerabek wrote:
I've had a look at the complex arctangent function in the RTS. It turned out that
- it raises a runtime error or returns an infinite imaginary part on arguments too close to the singularities +/- i, for example ArcTan (Cmplx (1e6 * MinReal, +/- 1))
With the improved Abs (and therefore Ln), this doesn't seem to happen anymore. But I wrote a test prorgam (emil9.pas) which shows some cases of problems even with the improved Abs. They all work ok with your code. I'm attaching the test program -- you might want to take a look at it and possible improve or extend it.
The following patch to p/rts/math.pas solves these problems (I hope it doesn't introduce others).
Thanks for the code. I'm putting it in the RTS.
To save your time, here is some mathematics behind my Complex_Arctan reimplementation:
[...]
Mathematically it all seems alright. I didn't try to prove the numeric stability, but my tests show that it's better than that of the previous version. Just one thing:
The "if c <= MinReal" branch (needed to avoid some overflows) is executed when |y|=1 and x^2 <= MinReal. In this case,
From the code, the condition for this case is:
| 1 - |y| | <= |x| and x^2 <= MinReal
To conclude |y| = 1, you need that EpsReal^2 >= MinReal, don't you? While this might be true on every FP system, would it cause problems in your code if not?
Frank