1/*
2 * IBM Accurate Mathematical Library
3 * written by International Business Machines Corp.
4 * Copyright (C) 2001-2018 Free Software Foundation, Inc.
5 *
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.
10 *
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.
15 *
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/>.
18 */
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"
38
39#ifndef SECTION
40# define SECTION
41#endif
42
43void
44SECTION
45__mptan (double x, mp_no *mpy, int p)
46{
47 int n;
48 mp_no mpw, mpc, mps;
49
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)
56 {
57 __dvd (&mpc, &mps, mpy, p);
58 mpy->d[0] *= -1;
59 }
60 /* tan is negative in this area. */
61 else
62 __dvd (&mps, &mpc, mpy, p);
63}
64