These subprograms compute the Euclidean length (l2
norm) of vector x, with scaling of input to avoid destructive
underflow and overflow.
x | Result | Subprogram |
Short-precision real | Short-precision real | SNRM2 |
Long-precision real | Long-precision real | DNRM2 |
Short-precision complex | Short-precision real | SCNRM2 |
Long-precision complex | Long-precision real | DZNRM2 |
Fortran | SNRM2 | DNRM2 | SCNRM2 | DZNRM2 (n, x, incx) |
C and C++ | snrm2 | dnrm2 | scnrm2 | dznrm2 (n, x, incx); |
PL/I | SNRM2 | DNRM2 | SCNRM2 | DZNRM2 (n, x, incx); |
Declare this function in your program as returning a value of the data type indicated in Table 46.
The Euclidean length (l2 norm) of vector x is expressed as follows, with scaling of input to avoid destructive underflow and overflow:
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 SNRM2 and SCNRM2, 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 and, if necessary, is unscaled.
Although these subroutines eliminate destructive underflow, nondestructive underflows may occur if the input elements differ greatly in magnitude. This does not affect accuracy, but it degrades performance. The system default is to mask underflow, which improves the performance of these subroutines.
None
n < 0
Workstations use workstation architecture precisions: ANSI/IEEE 32-bit and 64-bit binary floating-point format. The ranges are:
This example shows a vector, x, whose elements must be scaled to prevent overflow.
N X INCX | | | DNORM = DNRM2( 6 , X , 1 ) X = (0.68056D+200, 0.25521D+200, 0.34028D+200, 0.85071D+200, 0.25521D+200, 0.85071D+200)
DNORM = 0.1469D+201
This example shows a vector, x, whose elements must be scaled to prevent destructive underflow.
N X INCX | | | DNORM = DNRM2( 4 , X , 2 ) X = (0.10795D-200, . , 0.10795D-200, . , 0.10795D-200, . , 0.10795D-200)
DNORM = 0.21590D-200
This example shows a vector, x, with a stride of 0. The result in SNORM is:
N X INCX | | | SNORM = SNRM2( 4 , X , 0 ) X = (4.0)
SNORM = 8.0
This example shows a vector, x, containing complex numbers, and whose elements must be scaled to prevent overflow.
N X INCX | | | DZNORM = DZNRM2( 3 , X , 1 ) X = ((0.68056D+200, 0.25521D+200), (0.34028D+200, 0.85071D+200), (0.25521D+200, 0.85071D+200))
DZNORM = 0.1469D+201
This example shows a vector, x, containing complex numbers, and whose elements must be scaled to prevent destructive underflow.
N X INCX | | | DZNORM = DZNRM2( 2 , X , 2 ) X = ((0.10795D-200, 0.10795D-200), . , (0.10795D-200, 0.10795D-200))
DZNORM = 0.2159D-200