]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - contrib/libf2c/libF77/z_log.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / contrib / libf2c / libF77 / z_log.c
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 - +...)
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;
48       do
49         {
50           s0 = s;
51           u *= t2;
52           v += 2;
53           s += u / v - t * u / (v + 1);
54         }
55       while (s > s0);
56       r->r = s * t;
57     }
58 #endif
59 }