source: trunk/third/gcc/libf2c/libF77/z_log.c @ 16960

Revision 16960, 1.1 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16959, which included commits to RCS files with non-trunk default branches.
Line 
1#include "f2c.h"
2
3#ifdef KR_headers
4double log(), f__cabs(), atan2();
5VOID z_log(r, z) doublecomplex *r, *z;
6#else
7#undef abs
8#include "math.h"
9extern double f__cabs(double, double);
10void z_log(doublecomplex *r, doublecomplex *z)
11#endif
12{
13        double s, s0, t, t2, u, v;
14        double zi = z->i, zr = z->r;
15
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;
28                }
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 {
37
38#ifdef Comment
39
40        log(1+x) = x - x^2/2 + x^3/3 - x^4/4 + - ...
41
42                 = x(1 - x/2 + x^2/3 -+...)
43
44        [sqrt(y^2 + z^2) - 1] * [sqrt(y^2 + z^2) + 1] = y^2 + z^2 - 1, so
45
46        sqrt(y^2 + z^2) - 1 = (y^2 + z^2 - 1) / [sqrt(y^2 + z^2) + 1]
47
48#endif /*Comment*/
49
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;
61                }
62#endif
63        }
Note: See TracBrowser for help on using the repository browser.