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