snrm2.c
Go to the documentation of this file.
00001 /* snrm2.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 doublereal snrm2_(integer *n, real *x, integer *incx)
00017 {
00018     /* System generated locals */
00019     integer i__1, i__2;
00020     real ret_val, r__1;
00021 
00022     /* Builtin functions */
00023     double sqrt(doublereal);
00024 
00025     /* Local variables */
00026     integer ix;
00027     real ssq, norm, scale, absxi;
00028 
00029 /*     .. Scalar Arguments .. */
00030 /*     .. */
00031 /*     .. Array Arguments .. */
00032 /*     .. */
00033 
00034 /*  Purpose */
00035 /*  ======= */
00036 
00037 /*  SNRM2 returns the euclidean norm of a vector via the function */
00038 /*  name, so that */
00039 
00040 /*     SNRM2 := sqrt( x'*x ). */
00041 
00042 /*  Further Details */
00043 /*  =============== */
00044 
00045 /*  -- This version written on 25-October-1982. */
00046 /*     Modified on 14-October-1993 to inline the call to SLASSQ. */
00047 /*     Sven Hammarling, Nag Ltd. */
00048 
00049 
00050 /*     .. Parameters .. */
00051 /*     .. */
00052 /*     .. Local Scalars .. */
00053 /*     .. */
00054 /*     .. Intrinsic Functions .. */
00055 /*     .. */
00056     /* Parameter adjustments */
00057     --x;
00058 
00059     /* Function Body */
00060     if (*n < 1 || *incx < 1) {
00061         norm = 0.f;
00062     } else if (*n == 1) {
00063         norm = dabs(x[1]);
00064     } else {
00065         scale = 0.f;
00066         ssq = 1.f;
00067 /*        The following loop is equivalent to this call to the LAPACK */
00068 /*        auxiliary routine: */
00069 /*        CALL SLASSQ( N, X, INCX, SCALE, SSQ ) */
00070 
00071         i__1 = (*n - 1) * *incx + 1;
00072         i__2 = *incx;
00073         for (ix = 1; i__2 < 0 ? ix >= i__1 : ix <= i__1; ix += i__2) {
00074             if (x[ix] != 0.f) {
00075                 absxi = (r__1 = x[ix], dabs(r__1));
00076                 if (scale < absxi) {
00077 /* Computing 2nd power */
00078                     r__1 = scale / absxi;
00079                     ssq = ssq * (r__1 * r__1) + 1.f;
00080                     scale = absxi;
00081                 } else {
00082 /* Computing 2nd power */
00083                     r__1 = absxi / scale;
00084                     ssq += r__1 * r__1;
00085                 }
00086             }
00087 /* L10: */
00088         }
00089         norm = scale * sqrt(ssq);
00090     }
00091 
00092     ret_val = norm;
00093     return ret_val;
00094 
00095 /*     End of SNRM2. */
00096 
00097 } /* snrm2_ */


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