OSDN Git Service

PR c++/22494
[pf3gnuchains/gcc-fork.git] / libgcc-math / dbl-64 / mptan.c
1
2 /*
3  * IBM Accurate Mathematical Library
4  * written by International Business Machines Corp.
5  * Copyright (C) 2001 Free Software Foundation
6  *
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.
11  *
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.
16  *
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.
20  */
21 /**********************************************************************/
22 /* MODULE_NAME:mptan.c                                                */
23 /*                                                                    */
24 /* FUNCTION: mptan                                                    */
25 /*                                                                    */
26 /* FILES NEEDED: endian.h  mpa.h                                      */
27 /*               mpa.c  sincos32.c branred.c                          */
28 /*                                                                    */
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.                                                  */
36 /*                                                                    */
37 /**********************************************************************/
38 #include "endian.h"
39 #include "mpa.h"
40
41 int __mpranred(double, mp_no *, int);
42 void __c32(mp_no *, mp_no *, mp_no *, int);
43
44 void __mptan(double x, mp_no *mpy, int p) {
45
46   static const double Mone = -1.0;
47
48   int n;
49   mp_no mpw, mpc, mps;
50
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);
55     mpy->d[0] *= Mone;
56   }                          /* tan is negative in this area */
57   else  __dvd(&mps,&mpc,mpy,p);
58
59   return;
60 }