dlartg.c
Go to the documentation of this file.
00001 /* dlartg.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Subroutine */ int dlartg_(doublereal *f, doublereal *g, doublereal *cs, 
00017         doublereal *sn, doublereal *r__)
00018 {
00019     /* System generated locals */
00020     integer i__1;
00021     doublereal d__1, d__2;
00022 
00023     /* Builtin functions */
00024     double log(doublereal), pow_di(doublereal *, integer *), sqrt(doublereal);
00025 
00026     /* Local variables */
00027     integer i__;
00028     doublereal f1, g1, eps, scale;
00029     integer count;
00030     doublereal safmn2, safmx2;
00031     extern doublereal dlamch_(char *);
00032     doublereal safmin;
00033 
00034 
00035 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00036 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00037 /*     November 2006 */
00038 
00039 /*     .. Scalar Arguments .. */
00040 /*     .. */
00041 
00042 /*  Purpose */
00043 /*  ======= */
00044 
00045 /*  DLARTG generate a plane rotation so that */
00046 
00047 /*     [  CS  SN  ]  .  [ F ]  =  [ R ]   where CS**2 + SN**2 = 1. */
00048 /*     [ -SN  CS  ]     [ G ]     [ 0 ] */
00049 
00050 /*  This is a slower, more accurate version of the BLAS1 routine DROTG, */
00051 /*  with the following other differences: */
00052 /*     F and G are unchanged on return. */
00053 /*     If G=0, then CS=1 and SN=0. */
00054 /*     If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any */
00055 /*        floating point operations (saves work in DBDSQR when */
00056 /*        there are zeros on the diagonal). */
00057 
00058 /*  If F exceeds G in magnitude, CS will be positive. */
00059 
00060 /*  Arguments */
00061 /*  ========= */
00062 
00063 /*  F       (input) DOUBLE PRECISION */
00064 /*          The first component of vector to be rotated. */
00065 
00066 /*  G       (input) DOUBLE PRECISION */
00067 /*          The second component of vector to be rotated. */
00068 
00069 /*  CS      (output) DOUBLE PRECISION */
00070 /*          The cosine of the rotation. */
00071 
00072 /*  SN      (output) DOUBLE PRECISION */
00073 /*          The sine of the rotation. */
00074 
00075 /*  R       (output) DOUBLE PRECISION */
00076 /*          The nonzero component of the rotated vector. */
00077 
00078 /*  This version has a few statements commented out for thread safety */
00079 /*  (machine parameters are computed on each entry). 10 feb 03, SJH. */
00080 
00081 /*  ===================================================================== */
00082 
00083 /*     .. Parameters .. */
00084 /*     .. */
00085 /*     .. Local Scalars .. */
00086 /*     LOGICAL            FIRST */
00087 /*     .. */
00088 /*     .. External Functions .. */
00089 /*     .. */
00090 /*     .. Intrinsic Functions .. */
00091 /*     .. */
00092 /*     .. Save statement .. */
00093 /*     SAVE               FIRST, SAFMX2, SAFMIN, SAFMN2 */
00094 /*     .. */
00095 /*     .. Data statements .. */
00096 /*     DATA               FIRST / .TRUE. / */
00097 /*     .. */
00098 /*     .. Executable Statements .. */
00099 
00100 /*     IF( FIRST ) THEN */
00101     safmin = dlamch_("S");
00102     eps = dlamch_("E");
00103     d__1 = dlamch_("B");
00104     i__1 = (integer) (log(safmin / eps) / log(dlamch_("B")) / 2.);
00105     safmn2 = pow_di(&d__1, &i__1);
00106     safmx2 = 1. / safmn2;
00107 /*        FIRST = .FALSE. */
00108 /*     END IF */
00109     if (*g == 0.) {
00110         *cs = 1.;
00111         *sn = 0.;
00112         *r__ = *f;
00113     } else if (*f == 0.) {
00114         *cs = 0.;
00115         *sn = 1.;
00116         *r__ = *g;
00117     } else {
00118         f1 = *f;
00119         g1 = *g;
00120 /* Computing MAX */
00121         d__1 = abs(f1), d__2 = abs(g1);
00122         scale = max(d__1,d__2);
00123         if (scale >= safmx2) {
00124             count = 0;
00125 L10:
00126             ++count;
00127             f1 *= safmn2;
00128             g1 *= safmn2;
00129 /* Computing MAX */
00130             d__1 = abs(f1), d__2 = abs(g1);
00131             scale = max(d__1,d__2);
00132             if (scale >= safmx2) {
00133                 goto L10;
00134             }
00135 /* Computing 2nd power */
00136             d__1 = f1;
00137 /* Computing 2nd power */
00138             d__2 = g1;
00139             *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
00140             *cs = f1 / *r__;
00141             *sn = g1 / *r__;
00142             i__1 = count;
00143             for (i__ = 1; i__ <= i__1; ++i__) {
00144                 *r__ *= safmx2;
00145 /* L20: */
00146             }
00147         } else if (scale <= safmn2) {
00148             count = 0;
00149 L30:
00150             ++count;
00151             f1 *= safmx2;
00152             g1 *= safmx2;
00153 /* Computing MAX */
00154             d__1 = abs(f1), d__2 = abs(g1);
00155             scale = max(d__1,d__2);
00156             if (scale <= safmn2) {
00157                 goto L30;
00158             }
00159 /* Computing 2nd power */
00160             d__1 = f1;
00161 /* Computing 2nd power */
00162             d__2 = g1;
00163             *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
00164             *cs = f1 / *r__;
00165             *sn = g1 / *r__;
00166             i__1 = count;
00167             for (i__ = 1; i__ <= i__1; ++i__) {
00168                 *r__ *= safmn2;
00169 /* L40: */
00170             }
00171         } else {
00172 /* Computing 2nd power */
00173             d__1 = f1;
00174 /* Computing 2nd power */
00175             d__2 = g1;
00176             *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
00177             *cs = f1 / *r__;
00178             *sn = g1 / *r__;
00179         }
00180         if (abs(*f) > abs(*g) && *cs < 0.) {
00181             *cs = -(*cs);
00182             *sn = -(*sn);
00183             *r__ = -(*r__);
00184         }
00185     }
00186     return 0;
00187 
00188 /*     End of DLARTG */
00189 
00190 } /* dlartg_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:46