]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/ieee754/dbl-64/mplog.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / ieee754 / dbl-64 / mplog.c
CommitLineData
e4d82761
UD
1/*
2 * IBM Accurate Mathematical Library
aeb25823 3 * written by International Business Machines Corp.
b168057a 4 * Copyright (C) 2001-2015 Free Software Foundation, Inc.
e4d82761
UD
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
cc7375ce 8 * the Free Software Foundation; either version 2.1 of the License, or
e4d82761 9 * (at your option) any later version.
50944bca 10 *
e4d82761
UD
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
c6c6dd48 14 * GNU Lesser General Public License for more details.
e4d82761
UD
15 *
16 * You should have received a copy of the GNU Lesser General Public License
59ba27a6 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
e4d82761
UD
18 */
19/************************************************************************/
20/* */
21/* MODULE_NAME:mplog.c */
22/* */
23/* FUNCTIONS: mplog */
24/* */
25/* FILES NEEDED: endian.h mpa.h mplog.h */
26/* mpexp.c */
27/* */
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. */
34/* */
35/************************************************************************/
36#include "endian.h"
37#include "mpa.h"
38
11d6e2f2
SP
39void
40__mplog (mp_no *x, mp_no *y, int p)
41{
42 int i, m;
43 static const int mp[33] =
44 {
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
47 };
48 mp_no mpt1, mpt2;
e4d82761 49
11d6e2f2 50 /* Choose m. */
b76eb5f0 51 m = mp[p];
e4d82761 52
11d6e2f2
SP
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). */
55 __cpy (y, &mpt1, p);
56 for (i = 0; i < m; i++)
57 {
58 mpt1.d[0] = -mpt1.d[0];
59 __mpexp (&mpt1, &mpt2, p);
60 __mul (x, &mpt2, &mpt1, p);
107a5bf0 61 __sub (&mpt1, &__mpone, &mpt2, p);
11d6e2f2
SP
62 __add (y, &mpt2, &mpt1, p);
63 __cpy (&mpt1, y, p);
64 }
e4d82761 65}