* tree.h: Remove include of version.h
[official-gcc.git] / libf2c / libF77 / z_log.c
blobf56b12ed7e3957761ea41926baa8d5286c3e71f3
1 #include "f2c.h"
3 #undef abs
4 #include "math.h"
5 extern double f__cabs (double, double);
6 void
7 z_log (doublecomplex * r, doublecomplex * z)
9 double s, s0, t, t2, u, v;
10 double zi = z->i, zr = z->r;
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)
22 t = zi;
23 zi = zr;
24 zr = t;
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
36 #ifdef Comment
38 log (1 + x) = x - x ^ 2 / 2 + x ^ 3 / 3 - x ^ 4 / 4 + -...
39 = x (1 - x / 2 + x ^ 2 / 3 - +...)
40 [sqrt (y ^ 2 + z ^ 2) - 1] *[sqrt (y ^ 2 + z ^ 2) + 1] =
41 y ^ 2 + z ^ 2 - 1, so sqrt (y ^ 2 + z ^ 2) - 1 =
42 (y ^ 2 + z ^ 2 - 1) /[sqrt (y ^ 2 + z ^ 2) + 1]
43 #endif /*Comment */
44 t = ((zr * zr - 1.) + zi * zi) / (s + 1);
45 t2 = t * t;
46 s = 1. - 0.5 * t;
47 u = v = 1;
50 s0 = s;
51 u *= t2;
52 v += 2;
53 s += u / v - t * u / (v + 1);
55 while (s > s0);
56 r->r = s * t;
58 #endif