User's Manual

NUMERIC PROGRAMMING EXAMPLES
Cosine Uses Sine Code
To save code space, the cosine function uses most of the sine function code. The relation sin ( I A I +
7r
/2)
=
cos
(A)
is
used
to
convert the cosine a.rgument into a sine argument. Adding
7r
/2
to the angle
is
performed by adding 010
2
to the FPREM quotient bits identifying the argument's octant.
It
would be very inaccurate to add
7r
/2
to the cosine argument if it
was
very much different
from
7r/2.
Depending
on
which octant the argument falls in, a different relation
will
be used
in
the sine and
tangent functions. The program listings
show
which relations are used.
For the tangent function, the ratio produced by
FPTAN
will
be directly evaluated. The sine function
will use either a sine or cosine relation depending
on
which octant the angle fell into. On exit, these
functions will normally leave a divide instruction in progress to maintain concurrency.
If
the input angles are of a restricted range, such
as
from 0
to
45
degrees, then considerable optimiza-
tion
is
possible since full angle reduction and octant identification
is
not necessary.
All three functions begin
by
looking at the value given
to
them. Not a Number (NaN), infinity, or
empty registers must be specially treated. Unnormals need to be converted to normal values before the
FPTAN instruction will work correctly. Denormals
will
be converted to very small unnormals
that
do
work correctly for the FPT AN instruction. The sign of the angle
is
saved
to
control the sign of the
result.
Within the functions, close attention
was
paid to maintain concurrent execution of the 80287 and host.
The concurrent execution will effectively hide the execution time of the decision logic used in the
program.
iAPX286
MACRO
A.SSEMBLER
80287
Trignoltletric
Functions
SERIES-III
iAPX286
MACRO
ASSEMBLER
XI08
ASSEMBLY
OF
MODULE
TRIO
FUNCTIONS
OBJECT
MODULE
PLACED
IN
:
F3:
TRIO.
OBJ
-
ASSEMBLER
INVOKED BY:
ASM:!86.96;
F3:
TRIQ. AP2
LOC
OBJ
LINE
1 +1
2
3
4
5
6
7
SOURCE
ttitle("80287
Trignometric
Functions")
nama
trig_function~
public
sine.
cosine.
tangent
stack
10:
13:
51
OQ/25/83
PAGE
I
Ra.erve
local
space
8
SIIl_2B7
record
res1:
1,
tend3:
I.
top:
3.
tend:?:
1.
tend1:
1,
condO:
1.
0000
35CO;!b821A2DAOF
C9FE3F
OOOA
OOOOCOFF
9
tc
,..,2:
8
11
code
segment
el'"
public
12
13
Define
local
constants.
14
15
aven
16
pi_ltuarter
dt
3FFEC90FDAA2216BC:235R,
Pl/4
17
indefinite
dd
OFFCOOOOOR
,
Indefinite
special
.....
lu.
18 +1
$eJllct
Figure 4-7. Calculating Trigonometric Functions
4-18