~ubuntu-branches/ubuntu/lucid/igraph/lucid

« back to all changes in this revision

Viewing changes to src/lapack/dlartg.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Malaterre
  • Date: 2009-11-16 18:12:42 UTC
  • Revision ID: james.westby@ubuntu.com-20091116181242-mzv9p5fz9uj57xd1
Tags: upstream-0.5.3
ImportĀ upstreamĀ versionĀ 0.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  -- translated by f2c (version 20050501).
 
2
   You must link the resulting object file with libf2c:
 
3
        on Microsoft Windows system, link with libf2c.lib;
 
4
        on Linux or Unix systems, link with .../path/to/libf2c.a -lm
 
5
        or, if you install libf2c.a in a standard place, with -lf2c -lm
 
6
        -- in that order, at the end of the command line, as in
 
7
                cc *.o -lf2c -lm
 
8
        Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
 
9
 
 
10
                http://www.netlib.org/f2c/libf2c.zip
 
11
*/
 
12
 
 
13
#include "config.h"
 
14
#include "arpack_internal.h"
 
15
#include "f2c.h"
 
16
 
 
17
/* Subroutine */ int igraphdlartg_(doublereal *f, doublereal *g, doublereal *cs, 
 
18
        doublereal *sn, doublereal *r__)
 
19
{
 
20
    /* Initialized data */
 
21
 
 
22
    static logical first = TRUE_;
 
23
 
 
24
    /* System generated locals */
 
25
    integer i__1;
 
26
    doublereal d__1, d__2;
 
27
 
 
28
    /* Builtin functions */
 
29
    double log(doublereal), igraphpow_di(doublereal *, integer *), sqrt(doublereal);
 
30
 
 
31
    /* Local variables */
 
32
    static integer i__;
 
33
    static doublereal f1, g1, eps, scale;
 
34
    static integer count;
 
35
    static doublereal safmn2, safmx2;
 
36
    extern doublereal igraphdlamch_(char *);
 
37
    static doublereal safmin;
 
38
 
 
39
 
 
40
/*  -- LAPACK auxiliary routine (version 3.0) -- */
 
41
/*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
 
42
/*     Courant Institute, Argonne National Lab, and Rice University */
 
43
/*     September 30, 1994 */
 
44
 
 
45
/*     .. Scalar Arguments .. */
 
46
/*     .. */
 
47
 
 
48
/*  Purpose */
 
49
/*  ======= */
 
50
 
 
51
/*  DLARTG generate a plane rotation so that */
 
52
 
 
53
/*     [  CS  SN  ]  .  [ F ]  =  [ R ]   where CS**2 + SN**2 = 1. */
 
54
/*     [ -SN  CS  ]     [ G ]     [ 0 ] */
 
55
 
 
56
/*  This is a slower, more accurate version of the BLAS1 routine DROTG, */
 
57
/*  with the following other differences: */
 
58
/*     F and G are unchanged on return. */
 
59
/*     If G=0, then CS=1 and SN=0. */
 
60
/*     If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any */
 
61
/*        floating point operations (saves work in DBDSQR when */
 
62
/*        there are zeros on the diagonal). */
 
63
 
 
64
/*  If F exceeds G in magnitude, CS will be positive. */
 
65
 
 
66
/*  Arguments */
 
67
/*  ========= */
 
68
 
 
69
/*  F       (input) DOUBLE PRECISION */
 
70
/*          The first component of vector to be rotated. */
 
71
 
 
72
/*  G       (input) DOUBLE PRECISION */
 
73
/*          The second component of vector to be rotated. */
 
74
 
 
75
/*  CS      (output) DOUBLE PRECISION */
 
76
/*          The cosine of the rotation. */
 
77
 
 
78
/*  SN      (output) DOUBLE PRECISION */
 
79
/*          The sine of the rotation. */
 
80
 
 
81
/*  R       (output) DOUBLE PRECISION */
 
82
/*          The nonzero component of the rotated vector. */
 
83
 
 
84
/*  ===================================================================== */
 
85
 
 
86
/*     .. Parameters .. */
 
87
/*     .. */
 
88
/*     .. Local Scalars .. */
 
89
/*     .. */
 
90
/*     .. External Functions .. */
 
91
/*     .. */
 
92
/*     .. Intrinsic Functions .. */
 
93
/*     .. */
 
94
/*     .. Save statement .. */
 
95
/*     .. */
 
96
/*     .. Data statements .. */
 
97
/*     .. */
 
98
/*     .. Executable Statements .. */
 
99
 
 
100
    if (first) {
 
101
        first = FALSE_;
 
102
        safmin = igraphdlamch_("S");
 
103
        eps = igraphdlamch_("E");
 
104
        d__1 = igraphdlamch_("B");
 
105
        i__1 = (integer) (log(safmin / eps) / log(igraphdlamch_("B")) / 
 
106
                2.);
 
107
        safmn2 = igraphpow_di(&d__1, &i__1);
 
108
        safmx2 = 1. / safmn2;
 
109
    }
 
110
    if (*g == 0.) {
 
111
        *cs = 1.;
 
112
        *sn = 0.;
 
113
        *r__ = *f;
 
114
    } else if (*f == 0.) {
 
115
        *cs = 0.;
 
116
        *sn = 1.;
 
117
        *r__ = *g;
 
118
    } else {
 
119
        f1 = *f;
 
120
        g1 = *g;
 
121
/* Computing MAX */
 
122
        d__1 = abs(f1), d__2 = abs(g1);
 
123
        scale = max(d__1,d__2);
 
124
        if (scale >= safmx2) {
 
125
            count = 0;
 
126
L10:
 
127
            ++count;
 
128
            f1 *= safmn2;
 
129
            g1 *= safmn2;
 
130
/* Computing MAX */
 
131
            d__1 = abs(f1), d__2 = abs(g1);
 
132
            scale = max(d__1,d__2);
 
133
            if (scale >= safmx2) {
 
134
                goto L10;
 
135
            }
 
136
/* Computing 2nd power */
 
137
            d__1 = f1;
 
138
/* Computing 2nd power */
 
139
            d__2 = g1;
 
140
            *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
 
141
            *cs = f1 / *r__;
 
142
            *sn = g1 / *r__;
 
143
            i__1 = count;
 
144
            for (i__ = 1; i__ <= i__1; ++i__) {
 
145
                *r__ *= safmx2;
 
146
/* L20: */
 
147
            }
 
148
        } else if (scale <= safmn2) {
 
149
            count = 0;
 
150
L30:
 
151
            ++count;
 
152
            f1 *= safmx2;
 
153
            g1 *= safmx2;
 
154
/* Computing MAX */
 
155
            d__1 = abs(f1), d__2 = abs(g1);
 
156
            scale = max(d__1,d__2);
 
157
            if (scale <= safmn2) {
 
158
                goto L30;
 
159
            }
 
160
/* Computing 2nd power */
 
161
            d__1 = f1;
 
162
/* Computing 2nd power */
 
163
            d__2 = g1;
 
164
            *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
 
165
            *cs = f1 / *r__;
 
166
            *sn = g1 / *r__;
 
167
            i__1 = count;
 
168
            for (i__ = 1; i__ <= i__1; ++i__) {
 
169
                *r__ *= safmn2;
 
170
/* L40: */
 
171
            }
 
172
        } else {
 
173
/* Computing 2nd power */
 
174
            d__1 = f1;
 
175
/* Computing 2nd power */
 
176
            d__2 = g1;
 
177
            *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
 
178
            *cs = f1 / *r__;
 
179
            *sn = g1 / *r__;
 
180
        }
 
181
        if (abs(*f) > abs(*g) && *cs < 0.) {
 
182
            *cs = -(*cs);
 
183
            *sn = -(*sn);
 
184
            *r__ = -(*r__);
 
185
        }
 
186
    }
 
187
    return 0;
 
188
 
 
189
/*     End of DLARTG */
 
190
 
 
191
} /* igraphdlartg_ */
 
192