User's Manual

inter
NUMERIC PROGRAMMING EXAMPLES
FINAL ADJUSTMENTS
It
is
possible that the power function
(GeLPowec10)
could produce a scaling value such that it forms
a scaled result larger than the
ASCII
field could allow. For example, scaling 9.9999999999999999 X
10
4900
by 1.00000000000000010 X
10-
4883
would produce 1.00000000000000009 X 10". The scale
factor
is
within the accuracy of the
NPX
and the result
is
within the conversion accuracy, but it cannot
be represented in BCD format. This
is
why
there
is
a post-scaling test
on
the magnitude of the result.
The result can be multiplied or divided by
10,
depending
on
whether the result was too small or too
large, respectively.
Output Format
For maximum flexibility in output formats, the position of the decimal point
is
indicated
by
a binary
integer called the power value.
If
the power value
is
zero, then the decimal point
is
assumed to be at
the right of the rightmost digit. Power values greater than zero indicate
how
many trailing zeros are
not shown. For each unit below zero, move the decimal point to the left in the string.
The last step of the conversion
is
storing the result in BCD and indicating where the decimal point lies.
The BCD string
is
then unpacked into ASCII decimal characters. The ASCII sign
is
set corresponding
to the sign of the original value.
TRIGONOMETRIC CALCULATION EXAMPLES
The 80287 instruction set does not provide a complete set of trigonometric'functions
that
can be used
directly
in
calculations. Rather, the basic building blocks for implementing trigonometric functions are
provided by the
FPTAN
and
FPREM
instructions. The example in figure
4-7
shows
how
three trigon-
ometric functions (sine, cosine, and tangent) can
be
implementing using the 80287. All three functions
accept a valid angle argument between - 2
62
and +
262.
These functions may be called from
PL/M-286, Pascal-286, FORTRAN-286, or ASM286 routines.
These trigonometric functions use the partial tangent instruction together with trigonometric identities
to calculate the result. They are accurate to within
16
units of the
low
4 bits of an extended precision
value. The functions are coded for speed and small size, with tradeoffs available for greater accuracy.
FPT
AN and FPREM
These trigonometric functions use the FPTAN instruction of the NPX. FPTAN requires that the angle
argument be between
0 and 7r / 4 radians, 0 to
45
degrees. The
FPREM
instruction
is
used to reduce
the argument down to this range. The
low
three quotient bits set
by
FPREM
identify which octant the
original angle was in.
One
FPREM
instruction iteration can reduce angles of
10
18
radians or less in magnitude to
7r
/
4!
Larger
values can
be
reduced, but the meaning of the result
is
questionable, because any errors
in
the least
significant bits of
that
value represent changes of
45
degrees or more in the reduced angle.
4-17