Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / ieee754 / dbl-64 / mptan.c
blobaa16782c2cb52f8239e64833c8dc941fc98a9c28
1 /*
2 * IBM Accurate Mathematical Library
3 * written by International Business Machines Corp.
4 * Copyright (C) 2001-2014 Free Software Foundation, Inc.
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, see <http://www.gnu.org/licenses/>.
19 /**********************************************************************/
20 /* MODULE_NAME:mptan.c */
21 /* */
22 /* FUNCTION: mptan */
23 /* */
24 /* FILES NEEDED: endian.h mpa.h */
25 /* mpa.c sincos32.c branred.c */
26 /* */
27 /* Multi-Precision tan() function subroutine, for p=32. It is based */
28 /* on the routines mpranred() and c32(). mpranred() performs range */
29 /* reduction of a double number x into a multiple precision number */
30 /* y, such that y=x-n*pi/2, abs(y)<pi/4, n=0,+-1,+-2,.... c32() */
31 /* computes both sin(y), cos(y). tan(x) is either sin(y)/cos(y) */
32 /* or -cos(y)/sin(y). The precision of the result is of about 559 */
33 /* significant bits. */
34 /* */
35 /**********************************************************************/
36 #include "endian.h"
37 #include "mpa.h"
39 #ifndef SECTION
40 # define SECTION
41 #endif
43 void
44 SECTION
45 __mptan (double x, mp_no *mpy, int p)
47 int n;
48 mp_no mpw, mpc, mps;
50 /* Negative or positive result. */
51 n = __mpranred (x, &mpw, p) & 0x00000001;
52 /* Computing sin(x) and cos(x). */
53 __c32 (&mpw, &mpc, &mps, p);
54 /* Second or fourth quarter of unit circle. */
55 if (n)
57 __dvd (&mpc, &mps, mpy, p);
58 mpy->d[0] *= -1;
60 /* tan is negative in this area. */
61 else
62 __dvd (&mps, &mpc, mpy, p);