* config/netbsd.h (CPP_SPEC): Remove.
[official-gcc.git] / libf2c / libF77 / z_log.c
blob9dcc7f73fe5da8d1196d9fd2ad12a161cf6f9ea9
1 #include "f2c.h"
3 #ifdef KR_headers
4 double log(), f__cabs(), atan2();
5 VOID z_log(r, z) doublecomplex *r, *z;
6 #else
7 #undef abs
8 #include "math.h"
9 extern double f__cabs(double, double);
10 void z_log(doublecomplex *r, doublecomplex *z)
11 #endif
13 double s, s0, t, t2, u, v;
14 double zi = z->i, zr = z->r;
16 r->i = atan2(zi, zr);
17 #ifdef Pre20000310
18 r->r = log( f__cabs( zr, zi ) );
19 #else
20 if (zi < 0)
21 zi = -zi;
22 if (zr < 0)
23 zr = -zr;
24 if (zr < zi) {
25 t = zi;
26 zi = zr;
27 zr = t;
29 t = zi/zr;
30 s = zr * sqrt(1 + t*t);
31 /* now s = f__cabs(zi,zr), and zr = |zr| >= |zi| = zi */
32 if ((t = s - 1) < 0)
33 t = -t;
34 if (t > .01)
35 r->r = log(s);
36 else {
38 #ifdef Comment
40 log(1+x) = x - x^2/2 + x^3/3 - x^4/4 + - ...
42 = x(1 - x/2 + x^2/3 -+...)
44 [sqrt(y^2 + z^2) - 1] * [sqrt(y^2 + z^2) + 1] = y^2 + z^2 - 1, so
46 sqrt(y^2 + z^2) - 1 = (y^2 + z^2 - 1) / [sqrt(y^2 + z^2) + 1]
48 #endif /*Comment*/
50 t = ((zr*zr - 1.) + zi*zi) / (s + 1);
51 t2 = t*t;
52 s = 1. - 0.5*t;
53 u = v = 1;
54 do {
55 s0 = s;
56 u *= t2;
57 v += 2;
58 s += u/v - t*u/(v+1);
59 } while(s > s0);
60 r->r = s*t;
62 #endif