]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/dbl-64/mplog.c
Add script to update copyright notices and reformat some to facilitate its use.
[thirdparty/glibc.git] / sysdeps / ieee754 / dbl-64 / mplog.c
1
2 /*
3 * IBM Accurate Mathematical Library
4 * written by International Business Machines Corp.
5 * Copyright (C) 2001-2012 Free Software Foundation, Inc.
6 *
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.
11 *
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.
16 *
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/>.
19 */
20 /************************************************************************/
21 /* */
22 /* MODULE_NAME:mplog.c */
23 /* */
24 /* FUNCTIONS: mplog */
25 /* */
26 /* FILES NEEDED: endian.h mpa.h mplog.h */
27 /* mpexp.c */
28 /* */
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. */
35 /* */
36 /************************************************************************/
37 #include "endian.h"
38 #include "mpa.h"
39
40 void __mpexp(mp_no *, mp_no *, int);
41
42 void __mplog(mp_no *x, mp_no *y, int p) {
43 int i,m;
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};
46 mp_no mpt1,mpt2;
47
48 /* Choose m */
49 m = mp[p];
50
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). */
53 __cpy(y,&mpt1,p);
54 for (i=0; i<m; i++) {
55 mpt1.d[0]=-mpt1.d[0];
56 __mpexp(&mpt1,&mpt2,p);
57 __mul(x,&mpt2,&mpt1,p);
58 __sub(&mpt1,&mpone,&mpt2,p);
59 __add(y,&mpt2,&mpt1,p);
60 __cpy(&mpt1,y,p);
61 }
62 return;
63 }