1*901f3990SIngo Weinhold
2*901f3990SIngo Weinhold /*
3*901f3990SIngo Weinhold * IBM Accurate Mathematical Library
4*901f3990SIngo Weinhold * written by International Business Machines Corp.
5*901f3990SIngo Weinhold * Copyright (C) 2001 Free Software Foundation
6*901f3990SIngo Weinhold *
7*901f3990SIngo Weinhold * This program is free software; you can redistribute it and/or modify
8*901f3990SIngo Weinhold * it under the terms of the GNU Lesser General Public License as published by
9*901f3990SIngo Weinhold * the Free Software Foundation; either version 2.1 of the License, or
10*901f3990SIngo Weinhold * (at your option) any later version.
11*901f3990SIngo Weinhold *
12*901f3990SIngo Weinhold * This program is distributed in the hope that it will be useful,
13*901f3990SIngo Weinhold * but WITHOUT ANY WARRANTY; without even the implied warranty of
14*901f3990SIngo Weinhold * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*901f3990SIngo Weinhold * GNU Lesser General Public License for more details.
16*901f3990SIngo Weinhold *
17*901f3990SIngo Weinhold * You should have received a copy of the GNU Lesser General Public License
18*901f3990SIngo Weinhold * along with this program; if not, write to the Free Software
19*901f3990SIngo Weinhold * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20*901f3990SIngo Weinhold */
21*901f3990SIngo Weinhold /**********************************************************************/
22*901f3990SIngo Weinhold /* MODULE_NAME:mptan.c */
23*901f3990SIngo Weinhold /* */
24*901f3990SIngo Weinhold /* FUNCTION: mptan */
25*901f3990SIngo Weinhold /* */
26*901f3990SIngo Weinhold /* FILES NEEDED: endian.h mpa.h */
27*901f3990SIngo Weinhold /* mpa.c sincos32.c branred.c */
28*901f3990SIngo Weinhold /* */
29*901f3990SIngo Weinhold /* Multi-Precision tan() function subroutine, for p=32. It is based */
30*901f3990SIngo Weinhold /* on the routines mpranred() and c32(). mpranred() performs range */
31*901f3990SIngo Weinhold /* reduction of a double number x into a multiple precision number */
32*901f3990SIngo Weinhold /* y, such that y=x-n*pi/2, abs(y)<pi/4, n=0,+-1,+-2,.... c32() */
33*901f3990SIngo Weinhold /* computes both sin(y), cos(y). tan(x) is either sin(y)/cos(y) */
34*901f3990SIngo Weinhold /* or -cos(y)/sin(y). The precision of the result is of about 559 */
35*901f3990SIngo Weinhold /* significant bits. */
36*901f3990SIngo Weinhold /* */
37*901f3990SIngo Weinhold /**********************************************************************/
38*901f3990SIngo Weinhold #include "endian.h"
39*901f3990SIngo Weinhold #include "mpa.h"
40*901f3990SIngo Weinhold
41*901f3990SIngo Weinhold int __mpranred(double, mp_no *, int);
42*901f3990SIngo Weinhold void __c32(mp_no *, mp_no *, mp_no *, int);
43*901f3990SIngo Weinhold
__mptan(double x,mp_no * mpy,int p)44*901f3990SIngo Weinhold void __mptan(double x, mp_no *mpy, int p) {
45*901f3990SIngo Weinhold
46*901f3990SIngo Weinhold static const double MONE = -1.0;
47*901f3990SIngo Weinhold
48*901f3990SIngo Weinhold int n;
49*901f3990SIngo Weinhold mp_no mpw, mpc, mps;
50*901f3990SIngo Weinhold
51*901f3990SIngo Weinhold n = __mpranred(x, &mpw, p) & 0x00000001; /* negative or positive result */
52*901f3990SIngo Weinhold __c32(&mpw, &mpc, &mps, p); /* computing sin(x) and cos(x) */
53*901f3990SIngo Weinhold if (n) /* second or fourth quarter of unit circle */
54*901f3990SIngo Weinhold { __dvd(&mpc,&mps,mpy,p);
55*901f3990SIngo Weinhold mpy->d[0] *= MONE;
56*901f3990SIngo Weinhold } /* tan is negative in this area */
57*901f3990SIngo Weinhold else __dvd(&mps,&mpc,mpy,p);
58*901f3990SIngo Weinhold
59*901f3990SIngo Weinhold return;
60*901f3990SIngo Weinhold }
61