slartg.c
Go to the documentation of this file.
00001 /* slartg.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 slartg_(real *f, real *g, real *cs, real *sn, real *r__)
00017 {
00018     /* System generated locals */
00019     integer i__1;
00020     real r__1, r__2;
00021 
00022     /* Builtin functions */
00023     double log(doublereal), pow_ri(real *, integer *), sqrt(doublereal);
00024 
00025     /* Local variables */
00026     integer i__;
00027     real f1, g1, eps, scale;
00028     integer count;
00029     real safmn2, safmx2;
00030     extern doublereal slamch_(char *);
00031     real safmin;
00032 
00033 
00034 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00035 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00036 /*     November 2006 */
00037 
00038 /*     .. Scalar Arguments .. */
00039 /*     .. */
00040 
00041 /*  Purpose */
00042 /*  ======= */
00043 
00044 /*  SLARTG generate a plane rotation so that */
00045 
00046 /*     [  CS  SN  ]  .  [ F ]  =  [ R ]   where CS**2 + SN**2 = 1. */
00047 /*     [ -SN  CS  ]     [ G ]     [ 0 ] */
00048 
00049 /*  This is a slower, more accurate version of the BLAS1 routine SROTG, */
00050 /*  with the following other differences: */
00051 /*     F and G are unchanged on return. */
00052 /*     If G=0, then CS=1 and SN=0. */
00053 /*     If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any */
00054 /*        floating point operations (saves work in SBDSQR when */
00055 /*        there are zeros on the diagonal). */
00056 
00057 /*  If F exceeds G in magnitude, CS will be positive. */
00058 
00059 /*  Arguments */
00060 /*  ========= */
00061 
00062 /*  F       (input) REAL */
00063 /*          The first component of vector to be rotated. */
00064 
00065 /*  G       (input) REAL */
00066 /*          The second component of vector to be rotated. */
00067 
00068 /*  CS      (output) REAL */
00069 /*          The cosine of the rotation. */
00070 
00071 /*  SN      (output) REAL */
00072 /*          The sine of the rotation. */
00073 
00074 /*  R       (output) REAL */
00075 /*          The nonzero component of the rotated vector. */
00076 
00077 /*  This version has a few statements commented out for thread safety */
00078 /*  (machine parameters are computed on each entry). 10 feb 03, SJH. */
00079 
00080 /*  ===================================================================== */
00081 
00082 /*     .. Parameters .. */
00083 /*     .. */
00084 /*     .. Local Scalars .. */
00085 /*     LOGICAL            FIRST */
00086 /*     .. */
00087 /*     .. External Functions .. */
00088 /*     .. */
00089 /*     .. Intrinsic Functions .. */
00090 /*     .. */
00091 /*     .. Save statement .. */
00092 /*     SAVE               FIRST, SAFMX2, SAFMIN, SAFMN2 */
00093 /*     .. */
00094 /*     .. Data statements .. */
00095 /*     DATA               FIRST / .TRUE. / */
00096 /*     .. */
00097 /*     .. Executable Statements .. */
00098 
00099 /*     IF( FIRST ) THEN */
00100     safmin = slamch_("S");
00101     eps = slamch_("E");
00102     r__1 = slamch_("B");
00103     i__1 = (integer) (log(safmin / eps) / log(slamch_("B")) / 2.f);
00104     safmn2 = pow_ri(&r__1, &i__1);
00105     safmx2 = 1.f / safmn2;
00106 /*        FIRST = .FALSE. */
00107 /*     END IF */
00108     if (*g == 0.f) {
00109         *cs = 1.f;
00110         *sn = 0.f;
00111         *r__ = *f;
00112     } else if (*f == 0.f) {
00113         *cs = 0.f;
00114         *sn = 1.f;
00115         *r__ = *g;
00116     } else {
00117         f1 = *f;
00118         g1 = *g;
00119 /* Computing MAX */
00120         r__1 = dabs(f1), r__2 = dabs(g1);
00121         scale = dmax(r__1,r__2);
00122         if (scale >= safmx2) {
00123             count = 0;
00124 L10:
00125             ++count;
00126             f1 *= safmn2;
00127             g1 *= safmn2;
00128 /* Computing MAX */
00129             r__1 = dabs(f1), r__2 = dabs(g1);
00130             scale = dmax(r__1,r__2);
00131             if (scale >= safmx2) {
00132                 goto L10;
00133             }
00134 /* Computing 2nd power */
00135             r__1 = f1;
00136 /* Computing 2nd power */
00137             r__2 = g1;
00138             *r__ = sqrt(r__1 * r__1 + r__2 * r__2);
00139             *cs = f1 / *r__;
00140             *sn = g1 / *r__;
00141             i__1 = count;
00142             for (i__ = 1; i__ <= i__1; ++i__) {
00143                 *r__ *= safmx2;
00144 /* L20: */
00145             }
00146         } else if (scale <= safmn2) {
00147             count = 0;
00148 L30:
00149             ++count;
00150             f1 *= safmx2;
00151             g1 *= safmx2;
00152 /* Computing MAX */
00153             r__1 = dabs(f1), r__2 = dabs(g1);
00154             scale = dmax(r__1,r__2);
00155             if (scale <= safmn2) {
00156                 goto L30;
00157             }
00158 /* Computing 2nd power */
00159             r__1 = f1;
00160 /* Computing 2nd power */
00161             r__2 = g1;
00162             *r__ = sqrt(r__1 * r__1 + r__2 * r__2);
00163             *cs = f1 / *r__;
00164             *sn = g1 / *r__;
00165             i__1 = count;
00166             for (i__ = 1; i__ <= i__1; ++i__) {
00167                 *r__ *= safmn2;
00168 /* L40: */
00169             }
00170         } else {
00171 /* Computing 2nd power */
00172             r__1 = f1;
00173 /* Computing 2nd power */
00174             r__2 = g1;
00175             *r__ = sqrt(r__1 * r__1 + r__2 * r__2);
00176             *cs = f1 / *r__;
00177             *sn = g1 / *r__;
00178         }
00179         if (dabs(*f) > dabs(*g) && *cs < 0.f) {
00180             *cs = -(*cs);
00181             *sn = -(*sn);
00182             *r__ = -(*r__);
00183         }
00184     }
00185     return 0;
00186 
00187 /*     End of SLARTG */
00188 
00189 } /* slartg_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:11