LAPACK  3.9.1
LAPACK: Linear Algebra PACKage
snrm2.f
Go to the documentation of this file.
1 *> \brief \b SNRM2
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 * Definition:
9 * ===========
10 *
11 * REAL FUNCTION SNRM2(N,X,INCX)
12 *
13 * .. Scalar Arguments ..
14 * INTEGER INCX,N
15 * ..
16 * .. Array Arguments ..
17 * REAL X(*)
18 * ..
19 *
20 *
21 *> \par Purpose:
22 * =============
23 *>
24 *> \verbatim
25 *>
26 *> SNRM2 returns the euclidean norm of a vector via the function
27 *> name, so that
28 *>
29 *> SNRM2 := sqrt( x'*x ).
30 *> \endverbatim
31 *
32 * Arguments:
33 * ==========
34 *
35 *> \param[in] N
36 *> \verbatim
37 *> N is INTEGER
38 *> number of elements in input vector(s)
39 *> \endverbatim
40 *>
41 *> \param[in] X
42 *> \verbatim
43 *> X is REAL array, dimension ( 1 + ( N - 1 )*abs( INCX ) )
44 *> \endverbatim
45 *>
46 *> \param[in] INCX
47 *> \verbatim
48 *> INCX is INTEGER
49 *> storage spacing between elements of SX
50 *> \endverbatim
51 *
52 * Authors:
53 * ========
54 *
55 *> \author Univ. of Tennessee
56 *> \author Univ. of California Berkeley
57 *> \author Univ. of Colorado Denver
58 *> \author NAG Ltd.
59 *
60 *> \ingroup single_blas_level1
61 *
62 *> \par Further Details:
63 * =====================
64 *>
65 *> \verbatim
66 *>
67 *> -- This version written on 25-October-1982.
68 *> Modified on 14-October-1993 to inline the call to SLASSQ.
69 *> Sven Hammarling, Nag Ltd.
70 *> \endverbatim
71 *>
72 * =====================================================================
73  REAL function snrm2(n,x,incx)
74 *
75 * -- Reference BLAS level1 routine --
76 * -- Reference BLAS is a software package provided by Univ. of Tennessee, --
77 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
78 *
79 * .. Scalar Arguments ..
80  INTEGER incx,n
81 * ..
82 * .. Array Arguments ..
83  REAL x(*)
84 * ..
85 *
86 * =====================================================================
87 *
88 * .. Parameters ..
89  REAL one,zero
90  parameter(one=1.0e+0,zero=0.0e+0)
91 * ..
92 * .. Local Scalars ..
93  REAL absxi,norm,scale,ssq
94  INTEGER ix
95 * ..
96 * .. Intrinsic Functions ..
97  INTRINSIC abs,sqrt
98 * ..
99  IF (n.LT.1 .OR. incx.LT.1) THEN
100  norm = zero
101  ELSE IF (n.EQ.1) THEN
102  norm = abs(x(1))
103  ELSE
104  scale = zero
105  ssq = one
106 * The following loop is equivalent to this call to the LAPACK
107 * auxiliary routine:
108 * CALL SLASSQ( N, X, INCX, SCALE, SSQ )
109 *
110  DO 10 ix = 1,1 + (n-1)*incx,incx
111  IF (x(ix).NE.zero) THEN
112  absxi = abs(x(ix))
113  IF (scale.LT.absxi) THEN
114  ssq = one + ssq* (scale/absxi)**2
115  scale = absxi
116  ELSE
117  ssq = ssq + (absxi/scale)**2
118  END IF
119  END IF
120  10 CONTINUE
121  norm = scale*sqrt(ssq)
122  END IF
123 *
124  snrm2 = norm
125  RETURN
126 *
127 * End of SNRM2.
128 *
129  END
real function snrm2(N, X, INCX)
SNRM2
Definition: snrm2.f:74