| 1 |
/* ./src_f77/snrm2.f -- translated by f2c (version 20030320). |
| 2 |
You must link the resulting object file with the libraries: |
| 3 |
-lf2c -lm (in that order) |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <punc/vf2c.h> |
| 7 |
|
| 8 |
doublereal snrm2_(integer *n, real *x, integer *incx) |
| 9 |
{ |
| 10 |
/* System generated locals */ |
| 11 |
integer i__1, i__2; |
| 12 |
real ret_val, r__1; |
| 13 |
|
| 14 |
/* Builtin functions */ |
| 15 |
double sqrt(doublereal); |
| 16 |
|
| 17 |
/* Local variables */ |
| 18 |
static integer ix; |
| 19 |
static real ssq, norm, scale, absxi; |
| 20 |
|
| 21 |
/* .. Scalar Arguments .. */ |
| 22 |
/* .. Array Arguments .. */ |
| 23 |
/* .. */ |
| 24 |
|
| 25 |
/* SNRM2 returns the euclidean norm of a vector via the function */ |
| 26 |
/* name, so that */ |
| 27 |
|
| 28 |
/* SNRM2 := sqrt( x'*x ) */ |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
/* -- This version written on 25-October-1982. */ |
| 33 |
/* Modified on 14-October-1993 to inline the call to SLASSQ. */ |
| 34 |
/* Sven Hammarling, Nag Ltd. */ |
| 35 |
|
| 36 |
|
| 37 |
/* .. Parameters .. */ |
| 38 |
/* .. Local Scalars .. */ |
| 39 |
/* .. Intrinsic Functions .. */ |
| 40 |
/* .. */ |
| 41 |
/* .. Executable Statements .. */ |
| 42 |
/* Parameter adjustments */ |
| 43 |
--x; |
| 44 |
|
| 45 |
/* Function Body */ |
| 46 |
if (*n < 1 || *incx < 1) { |
| 47 |
norm = 0.f; |
| 48 |
} else if (*n == 1) { |
| 49 |
norm = dabs(x[1]); |
| 50 |
} else { |
| 51 |
scale = 0.f; |
| 52 |
ssq = 1.f; |
| 53 |
/* The following loop is equivalent to this call to the LAPACK */ |
| 54 |
/* auxiliary routine: */ |
| 55 |
/* CALL SLASSQ( N, X, INCX, SCALE, SSQ ) */ |
| 56 |
|
| 57 |
i__1 = (*n - 1) * *incx + 1; |
| 58 |
i__2 = *incx; |
| 59 |
for (ix = 1; i__2 < 0 ? ix >= i__1 : ix <= i__1; ix += i__2) { |
| 60 |
if (x[ix] != 0.f) { |
| 61 |
absxi = (r__1 = x[ix], dabs(r__1)); |
| 62 |
if (scale < absxi) { |
| 63 |
/* Computing 2nd power */ |
| 64 |
r__1 = scale / absxi; |
| 65 |
ssq = ssq * (r__1 * r__1) + 1.f; |
| 66 |
scale = absxi; |
| 67 |
} else { |
| 68 |
/* Computing 2nd power */ |
| 69 |
r__1 = absxi / scale; |
| 70 |
ssq += r__1 * r__1; |
| 71 |
} |
| 72 |
} |
| 73 |
/* L10: */ |
| 74 |
} |
| 75 |
norm = scale * sqrt(ssq); |
| 76 |
} |
| 77 |
|
| 78 |
ret_val = norm; |
| 79 |
return ret_val; |
| 80 |
|
| 81 |
/* End of SNRM2. */ |
| 82 |
|
| 83 |
} /* snrm2_ */ |
| 84 |
|