These subprograms compute the euclidean length (l2
norm) of vector x with no scaling of input.
x | Result | Subprogram |
Short-precision real | Short-precision real | SNORM2 |
Long-precision real | Long-precision real | DNORM2 |
Short-precision complex | Short-precision real | CNORM2 |
Long-precision complex | Long-precision real | ZNORM2 |
Fortran | SNORM2 | DNORM2 | CNORM2 | ZNORM2 (n, x, incx) |
C and C++ | snorm2 | dnorm2 | cnorm2 | znorm2 (n, x, incx); |
PL/I | SNORM2 | DNORM2 | CNORM2 | ZNORM2 (n, x, incx); |
The euclidean length (l2 norm) of vector x is expressed as follows with no scaling of input:
See reference [79]. The result is returned as the function value. If n is 0, then 0.0 is returned as the value of the function.
For SNORM2 and CNORM2, the sum of the squares of the absolute values of the elements is accumulated in long-precision. The square root of this long-precision sum is then computed.
This subroutine should not be used if the values in vector x do not conform to the restriction given in Notes.
None
n < 0
This example shows a vector, x, with a stride of 1.
N X INCX | | | SNORM = SNORM2( 6 , X , 1 ) X = (3.0, 4.0, 1.0, 8.0, 1.0, 3.0)
SNORM = 10.0
This example shows a vector, x, with a stride greater than 1.
N X INCX | | | SNORM = SNORM2( 6 , X , 2 ) X = (3.0, . , 4.0, . , 1.0, . , 8.0, . , 1.0, . , 3.0)
SNORM = 10.0
This example shows a vector, x, with a stride of 0. The result in SNORM is:
N X INCX | | | SNORM = SNORM2( 4 , X , 0 ) X = (4.0)
SNORM = 8.0
This example shows a vector, x, containing complex numbers and having a stride of 1.
N X INCX | | | CNORM = CNORM2( 3 , X , 1 ) X = ((3.0, 4.0), (1.0, 8.0), (-1.0, 3.0))
CNORM = 10.0