HP MLIB User's Guide Vol. 1 7th Ed.
Chapter 2 Basic Vector Operations 143
Swap two vectors SSWAP/DSWAP/ISWAP/CSWAP/ZSWAP
incx Increment for the array x, incx ≠ 0:
incx > 0 x is stored forward in array x; that is,
x
i
is stored in x((i−1)×incx+1).
incx < 0 x is stored backward in array x; that
is, x
i
is stored in x((i−n)×incx+1).
Use incx = 1 if the vector x is stored contiguously in
array x; that is, if x
i
is stored in x(i). Refer to “BLAS
Indexing Conventions” in the introduction to this
chapter.
y Array of length leny = (n−1)×|incy|+1 containing the
n-vector y.
incy Increment for the array y, incy ≠ 0:
incy > 0 y is stored forward in array y; that is,
y
i
is stored in y((i−1)×incy+1).
incy < 0 y is stored backward in array y; that
is, y
i
is stored in y((i−n)×incy+1).
Use incy = 1 if the vector y is stored contiguously in
array y; that is, if y
i
is stored in y(i). Refer to “BLAS
Indexing Conventions” in the introduction to this
chapter.
Output x and y If n ≤ 0, then x and y are unchanged. Otherwise, x and
y are interchanged in x and y.
Notes The result is unspecified if incx = 0 or incy = 0 or if x and y overlap such that
any element of x shares a memory location with any element of y.
Fortran
Equivalent
SUBROUTINE SSWAP (N, X,INCX, Y,INCY)
REAL*4 TEMP,X(*),Y(*)
IF ( N .LE. 0 ) RETURN
IX = 1
IY = 1
IF ( INCX .LT. 0 ) IX = 1 - (N-1) * INCX
IF ( INCY .LT. 0 ) IY = 1 - (N-1) * INCY
DO 10 I = 1, N
TEMP = X(IX)
X(IX) = Y(IY)
Y(IY) = TEMP
IX = IX + INCX
IY = IY + INCY
10 CONTINUE
RETURN
END