]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/dbl-64/mplog.c
3 * IBM Accurate Mathematical Library
4 * written by International Business Machines Corp.
5 * Copyright (C) 2001-2012 Free Software Foundation, Inc.
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.
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.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 /************************************************************************/
22 /* MODULE_NAME:mplog.c */
24 /* FUNCTIONS: mplog */
26 /* FILES NEEDED: endian.h mpa.h mplog.h */
29 /* Multi-Precision logarithm function subroutine (for precision p >= 4, */
30 /* 2**(-1024) < x < 2**1024) and x is outside of the interval */
31 /* [1-2**(-54),1+2**(-54)]. Upon entry, x should be set to the */
32 /* multi-precision value of the input and y should be set into a multi- */
33 /* precision value of an approximation of log(x) with relative error */
34 /* bound of at most 2**(-52). The routine improves the accuracy of y. */
36 /************************************************************************/
40 void __mpexp(mp_no
*, mp_no
*, int);
42 void __mplog(mp_no
*x
, mp_no
*y
, int p
) {
44 static const int mp
[33] = {0,0,0,0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
45 4,4,4,4,4,4,4,4,4,4,4,4,4,4};
51 /* Perform m newton iterations to solve for y: exp(y)-x=0. */
52 /* The iterations formula is: y(n+1)=y(n)+(x*exp(-y(n))-1). */
56 __mpexp(&mpt1
,&mpt2
,p
);
57 __mul(x
,&mpt2
,&mpt1
,p
);
58 __sub(&mpt1
,&mpone
,&mpt2
,p
);
59 __add(y
,&mpt2
,&mpt1
,p
);