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 /************************************************************************/
21 /* MODULE_NAME:mplog.c */
23 /* FUNCTIONS: mplog */
25 /* FILES NEEDED: endian.h mpa.h mplog.h */
28 /* Multi-Precision logarithm function subroutine (for precision p >= 4, */
29 /* 2**(-1024) < x < 2**1024) and x is outside of the interval */
30 /* [1-2**(-54),1+2**(-54)]. Upon entry, x should be set to the */
31 /* multi-precision value of the input and y should be set into a multi- */
32 /* precision value of an approximation of log(x) with relative error */
33 /* bound of at most 2**(-52). The routine improves the accuracy of y. */
35 /************************************************************************/
40 __mplog (mp_no
*x
, mp_no
*y
, int p
)
43 static const int mp
[33] =
45 0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
46 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
53 /* Perform m newton iterations to solve for y: exp(y) - x = 0. The
54 iterations formula is: y(n + 1) = y(n) + (x * exp(-y(n)) - 1). */
56 for (i
= 0; i
< m
; i
++)
58 mpt1
.d
[0] = -mpt1
.d
[0];
59 __mpexp (&mpt1
, &mpt2
, p
);
60 __mul (x
, &mpt2
, &mpt1
, p
);
61 __sub (&mpt1
, &mpone
, &mpt2
, p
);
62 __add (y
, &mpt2
, &mpt1
, p
);