| 1 | #include "f2c.h"
|
|---|
| 2 |
|
|---|
| 3 | #undef abs
|
|---|
| 4 | #include "math.h"
|
|---|
| 5 | extern double f__cabs (double, double);
|
|---|
| 6 | void
|
|---|
| 7 | z_log (doublecomplex * r, doublecomplex * z)
|
|---|
| 8 | {
|
|---|
| 9 | double s, s0, t, t2, u, v;
|
|---|
| 10 | double zi = z->i, zr = z->r;
|
|---|
| 11 |
|
|---|
| 12 | r->i = atan2 (zi, zr);
|
|---|
| 13 | #ifdef Pre20000310
|
|---|
| 14 | r->r = log (f__cabs (zr, zi));
|
|---|
| 15 | #else
|
|---|
| 16 | if (zi < 0)
|
|---|
| 17 | zi = -zi;
|
|---|
| 18 | if (zr < 0)
|
|---|
| 19 | zr = -zr;
|
|---|
| 20 | if (zr < zi)
|
|---|
| 21 | {
|
|---|
| 22 | t = zi;
|
|---|
| 23 | zi = zr;
|
|---|
| 24 | zr = t;
|
|---|
| 25 | }
|
|---|
| 26 | t = zi / zr;
|
|---|
| 27 | s = zr * sqrt (1 + t * t);
|
|---|
| 28 | /* now s = f__cabs(zi,zr), and zr = |zr| >= |zi| = zi */
|
|---|
| 29 | if ((t = s - 1) < 0)
|
|---|
| 30 | t = -t;
|
|---|
| 31 | if (t > .01)
|
|---|
| 32 | r->r = log (s);
|
|---|
| 33 | else
|
|---|
| 34 | {
|
|---|
| 35 |
|
|---|
| 36 | #ifdef Comment
|
|---|
| 37 |
|
|---|
| 38 | log (1 + x) = x - x ^ 2 / 2 + x ^ 3 / 3 - x ^ 4 / 4 + -...
|
|---|
| 39 | = x (1 - x / 2 + x ^ 2 / 3 - +...)
|
|---|
|
|---|