3 /* Subroutine */ int dlartg_(doublereal *f, doublereal *g, doublereal *cs,
4 doublereal *sn, doublereal *r__)
6 /* System generated locals */
10 /* Builtin functions */
11 double log(doublereal), pow_di(doublereal *, integer *), sqrt(doublereal);
15 doublereal f1, g1, scale;
17 static doublereal safmn2, safmx2;
18 extern doublereal dlamch_(char *);
19 static doublereal safmin, eps;
20 static volatile logical first = TRUE_;
22 /* -- LAPACK auxiliary routine (version 3.1) -- */
23 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
26 /* .. Scalar Arguments .. */
32 /* DLARTG generate a plane rotation so that */
34 /* [ CS SN ] . [ F ] = [ R ] where CS**2 + SN**2 = 1. */
35 /* [ -SN CS ] [ G ] [ 0 ] */
37 /* This is a slower, more accurate version of the BLAS1 routine DROTG, */
38 /* with the following other differences: */
39 /* F and G are unchanged on return. */
40 /* If G=0, then CS=1 and SN=0. */
41 /* If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any */
42 /* floating point operations (saves work in DBDSQR when */
43 /* there are zeros on the diagonal). */
45 /* If F exceeds G in magnitude, CS will be positive. */
50 /* F (input) DOUBLE PRECISION */
51 /* The first component of vector to be rotated. */
53 /* G (input) DOUBLE PRECISION */
54 /* The second component of vector to be rotated. */
56 /* CS (output) DOUBLE PRECISION */
57 /* The cosine of the rotation. */
59 /* SN (output) DOUBLE PRECISION */
60 /* The sine of the rotation. */
62 /* R (output) DOUBLE PRECISION */
63 /* The nonzero component of the rotated vector. */
65 /* This version has a few statements commented out for thread safety */
66 /* (machine parameters are computed on each entry). 10 feb 03, SJH. */
68 /* ===================================================================== */
70 /* .. Parameters .. */
72 /* .. Local Scalars .. */
75 /* .. External Functions .. */
77 /* .. Intrinsic Functions .. */
79 /* .. Save statement .. */
80 /* SAVE FIRST, SAFMX2, SAFMIN, SAFMN2 */
82 /* .. Data statements .. */
83 /* DATA FIRST / .TRUE. / */
85 /* .. Executable Statements .. */
87 /* IF( FIRST ) THEN */
89 safmin = dlamch_("S");
92 i__1 = (integer) (log(safmin / eps) / log(dlamch_("B")) / 2.);
93 safmn2 = pow_di(&d__1, &i__1);
103 } else if (*f == 0.) {
111 d__1 = abs(f1), d__2 = abs(g1);
112 scale = max(d__1,d__2);
113 if (scale >= safmx2) {
120 d__1 = abs(f1), d__2 = abs(g1);
121 scale = max(d__1,d__2);
122 if (scale >= safmx2) {
125 /* Computing 2nd power */
127 /* Computing 2nd power */
129 *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
133 for (i__ = 1; i__ <= i__1; ++i__) {
137 } else if (scale <= safmn2) {
144 d__1 = abs(f1), d__2 = abs(g1);
145 scale = max(d__1,d__2);
146 if (scale <= safmn2) {
149 /* Computing 2nd power */
151 /* Computing 2nd power */
153 *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
157 for (i__ = 1; i__ <= i__1; ++i__) {
162 /* Computing 2nd power */
164 /* Computing 2nd power */
166 *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
170 if (abs(*f) > abs(*g) && *cs < 0.) {