LAPACK  3.7.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 *> \date December 2016
61 *
62 *> \ingroup single_blas_level1
63 *
64 *> \par Further Details:
65 * =====================
66 *>
67 *> \verbatim
68 *>
69 *> -- This version written on 25-October-1982.
70 *> Modified on 14-October-1993 to inline the call to SLASSQ.
71 *> Sven Hammarling, Nag Ltd.
72 *> \endverbatim
73 *>
74 * =====================================================================
75  REAL FUNCTION snrm2(N,X,INCX)
76 *
77 * -- Reference BLAS level1 routine (version 3.7.0) --
78 * -- Reference BLAS is a software package provided by Univ. of Tennessee, --
79 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
80 * December 2016
81 *
82 * .. Scalar Arguments ..
83  INTEGER INCX,N
84 * ..
85 * .. Array Arguments ..
86  REAL X(*)
87 * ..
88 *
89 * =====================================================================
90 *
91 * .. Parameters ..
92  REAL ONE,ZERO
93  parameter(one=1.0e+0,zero=0.0e+0)
94 * ..
95 * .. Local Scalars ..
96  REAL ABSXI,NORM,SCALE,SSQ
97  INTEGER IX
98 * ..
99 * .. Intrinsic Functions ..
100  INTRINSIC abs,sqrt
101 * ..
102  IF (n.LT.1 .OR. incx.LT.1) THEN
103  norm = zero
104  ELSE IF (n.EQ.1) THEN
105  norm = abs(x(1))
106  ELSE
107  scale = zero
108  ssq = one
109 * The following loop is equivalent to this call to the LAPACK
110 * auxiliary routine:
111 * CALL SLASSQ( N, X, INCX, SCALE, SSQ )
112 *
113  DO 10 ix = 1,1 + (n-1)*incx,incx
114  IF (x(ix).NE.zero) THEN
115  absxi = abs(x(ix))
116  IF (scale.LT.absxi) THEN
117  ssq = one + ssq* (scale/absxi)**2
118  scale = absxi
119  ELSE
120  ssq = ssq + (absxi/scale)**2
121  END IF
122  END IF
123  10 CONTINUE
124  norm = scale*sqrt(ssq)
125  END IF
126 *
127  snrm2 = norm
128  RETURN
129 *
130 * End of SNRM2.
131 *
132  END
real function snrm2(N, X, INCX)
SNRM2
Definition: snrm2.f:76