SNRM2/DNRM2/SCNRM2/DZNRM2

 

Euclidean norm

 

INTEGER*8

n, incx

 

 

REAL*8

s, DZNRM2

 

COMPLEX*16

x(lenx)

 

 

s = DZNRM2(n, x, incx)

 

Input

n

 

Number of elements of vector x to be used in the

 

 

 

Euclidean norm. If n ≤ 0, the subprograms do not

 

 

 

reference x.

 

x

 

Array of length lenx = (n−1)⋅incx+1 containing the

 

 

 

n-vector x.

 

incx

 

Increment for the array x. x is stored forward in array x

 

 

 

with increment incx; that is, xi is stored in

 

 

 

x((i−1)⋅incx+1).

 

 

 

Use incx = 1 if the vector x is stored contiguously in

 

 

 

array x; that is, if xi is stored in x(i). Refer to “BLAS

 

 

 

Indexing Conventions” in the introduction to this

 

 

 

chapter.

 

Output

s

 

If n ≤ 0, then s = 0. Otherwise, s is the Euclidean norm

 

 

 

of x.

 

Fortran

 

REAL*4 FUNCTION SNRM2 ( N, X,INCX )

Equivalent

 

INTEGER*4 INCX, INCXA, IX, N

 

 

REAL*4 ABSXI, SCALE, SSQ, X(*)

 

 

IF ( N .GT. 1 ) THEN

 

 

INCXA = ABS ( INCX )

 

 

SCALE

= 0.0

 

 

 

SSQ

= 1.0

 

 

 

DO 10 IX = 1, 1 + (N-1)*INCXA, INCXA

 

 

IF ( X(IX) .NE.0.0 ) THEN

 

 

 

ABSXI = ABS ( X(IX) )

 

 

 

IF ( SCALE .LT. ABSXI ) THEN

 

 

 

SSQ

= 1.0 + SSQ * (SCALE/ABSXI) ** 2

 

 

 

SCALE = ABSXI

 

 

 

ELSE

 

 

 

 

SSQ

= SSQ + (ABSXI/SCALE) ** 2

 

 

 

END IF

 

 

 

END IF

 

 

10

CONTINUE

 

SNRM2 = SCALE

* SQRT ( SSQ )

ELSE IF ( N .EQ.

1 ) THEN

SNRM2 = ABS (

X(1) )

ELSE

 

SNRM2 = 0.0

 

END IF

 

RETURN

 

END

 

108HP MLIB User’s Guide