User's Manual

PROGRAMMING NUMERIC APPLICATIONS
Note that FSCALE assumes the scale factor
in
ST(l)
is
an integral value
in
the range
-2
15
:sX<2
1
'.
If
the value
is
not integral, but is in-range and
is
greater in magnitude than
1,
FSCALE uses the
nearest integer smaller in magnitude; i.e., it chops the value toward
O.
If
the value
is
out of range, or 0
< I X I <
1,
the instruction will produce an undefined result and
will
not signal an exception, ,The
recommended practice
is
to
load the scale factor from a word integer
to
ensure correct operation.
FPREM
FPREM (partial remainder) performs modulo division of the top stack element
by
the next stack
element, i.e.,
ST(l)
is
the modulus. FPREM produces
an
exact result; the precision exception
does
not
occur. The sign of the remainder
is
the same
as
the sign of the original dividend.
FPREM operates
by
performing successive scaled subtractions; obtaining the exact remainder when
the operands differ greatly
in
magnitude can consume large amounts of execution time. Because the
80287 can only be preempted between instructions, the remainder function could seriously increase
interrupt latency
in
these cases. Accordingly, the instruction
is
designed
to
be
executed iteratively
in
a
software-controlled loop.
FPREM can reduce a magnitude difference of up
to
2
64
in
one
execution.
If
FPREM produces a
remainder that
is
less than the modulus, the function
is
complete and bit
C2
of the status word condi-
tion code
is
cleared.
If
the function
is
incomplete, C2
is
set
to
1;
the result
in
ST
is
then called the
partial remainder. Software can inspect
C2
by
storing the status word
following
execution of FPREM
and re-execute the instruction (using the partial remainder
in
ST
as
the dividend), until C2
is
cleared.
Alternatively, a program can determine when the function
is
complete
by
comparing ST
to
ST(1).
If
ST>ST(1),then
FPREM must
be
executed again; if ST=ST(1), then the remainder
is
0;
if
ST<ST(I),
then the remainder
is
ST. A higher priority interrupting routine that needs the 80287 can force a
context switch between the instructions
in
the remainder
loop.
An important use
for
FPREM
is
to
reduce arguments (operands) of periodic transcendental functions
to the range permitted
by
these instructions. For example, the FPTAN (tangent) instruction requires
its argument
to
be
less than
7r
/4.
Using 7r
/4
as
a modulus, FPREM
will
reduce an argument
so
that it
is
in
range of FPTAN. Because FPREM produces an exact result, the argument reduction does not
introduce roundoff error into the calculation, even if several iterations are required
to
bring the argument
into range. (The rounding of
7r
does
not create the effect
of
a rounded argument, but of a rounded
period.)
FPREM also provides the least-significant three bits of the quotient generated
by
FPREM (in C
3
,
C
h
Co).
This
is
also important for transcendental argument reduction, because it locates the original angle
in
the correct one of eight 7r
/4
segments of the unit circle (see table
2-4).
If
the
quotient
is
less than
4,
then
CO
will
be
the value of
C3
before FPREM
was
executed.
If
the quotient
is
less
than
2,
then
C3
~,:m
be
the
\'~!!.!e
of
('!
hpfoTP FPREM
was
executed.
FRNDINT
FRNDINT
(round to integer) rounds the top stack element
to
an integer. For example, assume that
ST contains the 80287 real number encoding of the decimal value 155.625.
FRNDINT
will
change
the value
to
155
if the RC field of the control word
is
set
to
down
or chop,
or
to
156
if it
is
set
to
up
or nearest.
2-8