2 * IBM Accurate Mathematical Library
3 * written by International Business Machines Corp.
4 * Copyright (C) 2001 Free Software Foundation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 /********************************************************************/
22 /* MODULE_NAME: dosincos.c */
25 /* FUNCTIONS: dubsin */
28 /* FILES NEEDED: endian.h mydefs.h dla.h dosincos.h */
31 /* Routines compute sin() and cos() as Double-Length numbers */
32 /********************************************************************/
41 #include "math_private.h"
43 /***********************************************************************/
44 /* Routine receive Double-Length number (x+dx) and computing sin(x+dx) */
45 /* as Double-Length number and store it at array v .It computes it by */
46 /* arithmetic action on Double-Length numbers */
47 /*(x+dx) between 0 and PI/4 */
48 /***********************************************************************/
50 void __dubsin(double x
, double dx
, double v
[]) {
51 double r
,s
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
,d
,dd
,d2
,dd2
,e
,ee
,
52 sn
,ssn
,cs
,ccs
,ds
,dss
,dc
,dcc
;
64 /* sin(x+dx)=sin(Xi+t)=sin(Xi)*cos(t) + cos(Xi)sin(t) where t ->0 */
65 MUL2(d
,dd
,d
,dd
,d2
,dd2
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
67 ssn
=sincos
.x
[k
+1]; /* sin(Xi) and cos(Xi) */
68 cs
=sincos
.x
[k
+2]; /* */
69 ccs
=sincos
.x
[k
+3]; /* */
70 MUL2(d2
,dd2
,s7
.x
,ss7
.x
,ds
,dss
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
); /* Taylor */
71 ADD2(ds
,dss
,s5
.x
,ss5
.x
,ds
,dss
,r
,s
);
72 MUL2(d2
,dd2
,ds
,dss
,ds
,dss
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
); /* series */
73 ADD2(ds
,dss
,s3
.x
,ss3
.x
,ds
,dss
,r
,s
);
74 MUL2(d2
,dd2
,ds
,dss
,ds
,dss
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
); /* for sin */
75 MUL2(d
,dd
,ds
,dss
,ds
,dss
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
76 ADD2(ds
,dss
,d
,dd
,ds
,dss
,r
,s
); /* ds=sin(t) */
78 MUL2(d2
,dd2
,c8
.x
,cc8
.x
,dc
,dcc
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
); ;/* Taylor */
79 ADD2(dc
,dcc
,c6
.x
,cc6
.x
,dc
,dcc
,r
,s
);
80 MUL2(d2
,dd2
,dc
,dcc
,dc
,dcc
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
); /* series */
81 ADD2(dc
,dcc
,c4
.x
,cc4
.x
,dc
,dcc
,r
,s
);
82 MUL2(d2
,dd2
,dc
,dcc
,dc
,dcc
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
); /* for cos */
83 ADD2(dc
,dcc
,c2
.x
,cc2
.x
,dc
,dcc
,r
,s
);
84 MUL2(d2
,dd2
,dc
,dcc
,dc
,dcc
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
); /* dc=cos(t) */
86 MUL2(cs
,ccs
,ds
,dss
,e
,ee
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
87 MUL2(dc
,dcc
,sn
,ssn
,dc
,dcc
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
88 SUB2(e
,ee
,dc
,dcc
,e
,ee
,r
,s
);
89 ADD2(e
,ee
,sn
,ssn
,e
,ee
,r
,s
); /* e+ee=sin(x+dx) */
94 /**********************************************************************/
95 /* Routine receive Double-Length number (x+dx) and computes cos(x+dx) */
96 /* as Double-Length number and store it in array v .It computes it by */
97 /* arithmetic action on Double-Length numbers */
98 /*(x+dx) between 0 and PI/4 */
99 /**********************************************************************/
101 void __dubcos(double x
, double dx
, double v
[]) {
102 double r
,s
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
,d
,dd
,d2
,dd2
,e
,ee
,
103 sn
,ssn
,cs
,ccs
,ds
,dss
,dc
,dcc
;
110 k
= u
.i
[LOW_HALF
]<<2;
113 dd
=(x
-d
)+dx
; /* cos(x+dx)=cos(Xi+t)=cos(Xi)cos(t) - sin(Xi)sin(t) */
114 MUL2(d
,dd
,d
,dd
,d2
,dd2
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
115 sn
=sincos
.x
[k
]; /* */
116 ssn
=sincos
.x
[k
+1]; /* sin(Xi) and cos(Xi) */
117 cs
=sincos
.x
[k
+2]; /* */
118 ccs
=sincos
.x
[k
+3]; /* */
119 MUL2(d2
,dd2
,s7
.x
,ss7
.x
,ds
,dss
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
120 ADD2(ds
,dss
,s5
.x
,ss5
.x
,ds
,dss
,r
,s
);
121 MUL2(d2
,dd2
,ds
,dss
,ds
,dss
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
122 ADD2(ds
,dss
,s3
.x
,ss3
.x
,ds
,dss
,r
,s
);
123 MUL2(d2
,dd2
,ds
,dss
,ds
,dss
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
124 MUL2(d
,dd
,ds
,dss
,ds
,dss
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
125 ADD2(ds
,dss
,d
,dd
,ds
,dss
,r
,s
);
127 MUL2(d2
,dd2
,c8
.x
,cc8
.x
,dc
,dcc
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
128 ADD2(dc
,dcc
,c6
.x
,cc6
.x
,dc
,dcc
,r
,s
);
129 MUL2(d2
,dd2
,dc
,dcc
,dc
,dcc
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
130 ADD2(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cc
,c2
.x
,cc2
.x
,dc
,dcc
,r
,s
);
151 MUL2(d2
,dd2
,dc
,dcc
,dc
,dcc
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
152 MUL2(sn
,ssn
,ds
,dss
,e
,ee
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
153 MUL2(dc
,dcc
,cs
,ccs
,dc
,dcc
,p
,hx
,tx
,hy
,ty
,q
,c
,cc
);
154 ADD2(e
,ee
,dc
,dcc
,e
,ee
,r
,s
);
155 SUB2(cs
,ccs
,e
,ee
,e
,ee
,r
,s
);
160 /**********************************************************************/
161 /* Routine receive Double-Length number (x+dx) and computes cos(x+dx) */
162 /* as Double-Length number and store it in array v */
163 /**********************************************************************/
164 void __docos(double x
, double dx
, double v
[]) {
166 if (x
>0) {y
=x
; yy
=dx
;}
168 if (y
<0.5*hp0
.x
) /* y< PI/4 */
169 {__dubcos(y
,yy
,w
); v
[0]=w
[0]; v
[1]=w
[1];}
170 else if (y
<1.5*hp0
.x
) { /* y< 3/4 * PI */
171 p
=hp0
.x
-y
; /* p = PI/2 - y */
175 if (y
>0) {__dubsin(y
,yy
,w
); v
[0]=w
[0]; v
[1]=w
[1];}
176 /* cos(x) = sin ( 90 - x ) */
177 else {__dubsin(-y
,-yy
,w
); v
[0]=-w
[0]; v
[1]=-w
[1];
180 else { /* y>= 3/4 * PI */
181 p
=2.0*hp0
.x
-y
; /* p = PI- y */