2 * IBM Accurate Mathematical Library
3 * written by International Business Machines Corp.
4 * Copyright (C) 2001-2015 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 /******************************************************************/
21 /* MODULE_NAME:mpatan.c */
23 /* FUNCTIONS:mpatan */
25 /* FILES NEEDED: mpa.h endian.h mpatan.h */
28 /* Multi-Precision Atan function subroutine, for precision p >= 4.*/
29 /* The relative error of the result is bounded by 34.32*r**(1-p), */
31 /******************************************************************/
44 __mpatan (mp_no
*x
, mp_no
*y
, int p
)
52 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
53 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
54 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
58 mp_no mps
, mpsm
, mpt
, mpt1
, mpt2
, mpt3
;
60 /* Choose m and initiate mptwoim1. */
69 for (m
= 6; m
> 0; m
--)
71 if (dx
> __atan_xm
[m
].d
)
78 /* Reduce x m times. */
84 for (i
= 0; i
< m
; i
++)
86 __add (&__mpone
, &mpsm
, &mpt1
, p
);
87 __mpsqrt (&mpt1
, &mpt2
, p
);
88 __add (&mpt2
, &mpt2
, &mpt1
, p
);
89 __add (&__mptwo
, &mpsm
, &mpt2
, p
);
90 __add (&mpt1
, &mpt2
, &mpt3
, p
);
91 __dvd (&mpsm
, &mpt3
, &mpt1
, p
);
92 __cpy (&mpt1
, &mpsm
, p
);
94 __mpsqrt (&mpsm
, &mps
, p
);
98 /* Evaluate a truncated power series for Atan(s). */
100 mptwoim1
.d
[1] = __atan_twonm1
[p
].d
;
101 __dvd (&mpsm
, &mptwoim1
, &mpt
, p
);
102 for (i
= n
- 1; i
> 1; i
--)
105 __dvd (&mpsm
, &mptwoim1
, &mpt1
, p
);
106 __mul (&mpsm
, &mpt
, &mpt2
, p
);
107 __sub (&mpt1
, &mpt2
, &mpt
, p
);
109 __mul (&mps
, &mpt
, &mpt1
, p
);
110 __sub (&mps
, &mpt1
, &mpt
, p
);
112 /* Compute Atan(x). */
113 mptwoim1
.d
[1] = 1 << m
;
114 __mul (&mptwoim1
, &mpt
, y
, p
);