1999-09-18 10:51:31 +00:00
|
|
|
#include "f2c.h"
|
|
|
|
|
|
|
|
#ifdef KR_headers
|
|
|
|
double log(), f__cabs(), atan2();
|
1999-09-19 05:59:11 +00:00
|
|
|
VOID z_log(r, z) doublecomplex *r, *z;
|
1999-09-18 10:51:31 +00:00
|
|
|
#else
|
|
|
|
#undef abs
|
1999-09-19 05:59:11 +00:00
|
|
|
#include "math.h"
|
1999-09-18 10:51:31 +00:00
|
|
|
extern double f__cabs(double, double);
|
1999-09-19 05:59:11 +00:00
|
|
|
void z_log(doublecomplex *r, doublecomplex *z)
|
1999-09-18 10:51:31 +00:00
|
|
|
#endif
|
|
|
|
{
|
2001-12-18 04:13:58 +00:00
|
|
|
double s, s0, t, t2, u, v;
|
1999-09-19 05:59:11 +00:00
|
|
|
double zi = z->i, zr = z->r;
|
2001-12-18 04:13:58 +00:00
|
|
|
|
1999-09-19 05:59:11 +00:00
|
|
|
r->i = atan2(zi, zr);
|
2001-12-18 04:13:58 +00:00
|
|
|
#ifdef Pre20000310
|
1999-09-19 05:59:11 +00:00
|
|
|
r->r = log( f__cabs( zr, zi ) );
|
2001-12-18 04:13:58 +00:00
|
|
|
#else
|
|
|
|
if (zi < 0)
|
|
|
|
zi = -zi;
|
|
|
|
if (zr < 0)
|
|
|
|
zr = -zr;
|
|
|
|
if (zr < zi) {
|
|
|
|
t = zi;
|
|
|
|
zi = zr;
|
|
|
|
zr = t;
|
|
|
|
}
|
|
|
|
t = zi/zr;
|
|
|
|
s = zr * sqrt(1 + t*t);
|
|
|
|
/* now s = f__cabs(zi,zr), and zr = |zr| >= |zi| = zi */
|
|
|
|
if ((t = s - 1) < 0)
|
|
|
|
t = -t;
|
|
|
|
if (t > .01)
|
|
|
|
r->r = log(s);
|
|
|
|
else {
|
|
|
|
|
|
|
|
#ifdef Comment
|
|
|
|
|
|
|
|
log(1+x) = x - x^2/2 + x^3/3 - x^4/4 + - ...
|
|
|
|
|
|
|
|
= x(1 - x/2 + x^2/3 -+...)
|
|
|
|
|
|
|
|
[sqrt(y^2 + z^2) - 1] * [sqrt(y^2 + z^2) + 1] = y^2 + z^2 - 1, so
|
|
|
|
|
|
|
|
sqrt(y^2 + z^2) - 1 = (y^2 + z^2 - 1) / [sqrt(y^2 + z^2) + 1]
|
|
|
|
|
|
|
|
#endif /*Comment*/
|
|
|
|
|
|
|
|
t = ((zr*zr - 1.) + zi*zi) / (s + 1);
|
|
|
|
t2 = t*t;
|
|
|
|
s = 1. - 0.5*t;
|
|
|
|
u = v = 1;
|
|
|
|
do {
|
|
|
|
s0 = s;
|
|
|
|
u *= t2;
|
|
|
|
v += 2;
|
|
|
|
s += u/v - t*u/(v+1);
|
|
|
|
} while(s > s0);
|
|
|
|
r->r = s*t;
|
|
|
|
}
|
|
|
|
#endif
|
1999-09-19 05:59:11 +00:00
|
|
|
}
|