HP MLIB User's Guide Vol. 1 7th Ed.

Chapter 2 Basic Vector Operations 93
Extract fractional parts SFRAC/DFRAC
incy > 0 y is stored forward in array y; that is,
y
i
is stored in y((i1)×incy+1).
incy < 0 y is stored backward in array y; that
is, y
i
is stored in y((in)×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 y Array of length leny = (n1)×|incy|+1 containing the
n-vector y. If n 0, y is unchanged. Otherwise, y
i
is the
fractional part of x
i
.
Notes The fractional part of a number is either zero or of the same sign as the number.
Thus, the fractional parts of 1.4, 1.0, 0.6, and 2.0 are 0.4, 0.0, 0.6, and 0.0,
respectively. x and y can be the same array if incx = incy. Otherwise, the result
is unspecified if x and y overlap such that any element of x shares a memory
location with any element of y.
Fortran
Equivalent
SUBROUTINE SFRAC (N, X,INCX, Y,INCY)
REAL*4 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
Y(IY) = X(IX) - AINT ( X(IX) )
IX = IX + INCX
IY = IY + INCY
10 CONTINUE
RETURN
END
Example Extract the fractional parts of the elements of the REAL*8 vector x into y,
where x and y are vectors 10 elements long stored in one-dimensional arrays X
and Y of dimension 20.
INTEGER*4 N,INCX,INCY
REAL*8 X(20),Y(20)
N = 10
INCX = 1
INCY = 1
CALL DFRAC (N,X,INCX,Y,INCY)