about summary refs log tree commit diff
path: root/sysdeps/ieee754/dbl-64/mplog.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/ieee754/dbl-64/mplog.c')
-rw-r--r--sysdeps/ieee754/dbl-64/mplog.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/sysdeps/ieee754/dbl-64/mplog.c b/sysdeps/ieee754/dbl-64/mplog.c
new file mode 100644
index 0000000000..78aec799f2
--- /dev/null
+++ b/sysdeps/ieee754/dbl-64/mplog.c
@@ -0,0 +1,68 @@
+
+/*
+ * IBM Accurate Mathematical Library
+ * Copyright (c) International Business Machines Corp., 2001
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or 
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+ */
+/************************************************************************/
+/*                                                                      */
+/*     MODULE_NAME:mplog.c                                              */
+/*                                                                      */
+/*     FUNCTIONS:  mplog                                                */
+/*                                                                      */
+/*     FILES NEEDED: endian.h mpa.h  mplog.h                            */
+/*                    mpexp.c                                           */
+/*                                                                      */
+/* Multi-Precision logarithm function subroutine (for precision p >= 4, */
+/* 2**(-1024) < x < 2**1024) and x is outside of the interval           */
+/* [1-2**(-54),1+2**(-54)]. Upon entry, x should be set to the          */
+/* multi-precision value of the input and y should be set into a multi- */
+/* precision value of an approximation of log(x) with relative error    */
+/* bound of at most 2**(-52). The routine improves the accuracy of y.   */
+/*                                                                      */
+/************************************************************************/
+#include "endian.h"
+#include "mpa.h"
+
+void mpexp(mp_no *, mp_no *, int);
+
+void mplog(mp_no *x, mp_no *y, int p) {
+#include "mplog.h"
+  int i,j,k,m,m1,m2,n;
+  double a,b;
+  static const int mp[33] = {0,0,0,0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
+                             4,4,4,4,4,4,4,4,4,4,4,4,4,4};
+  mp_no mpone = {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.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.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,};
+  mp_no mpt1,mpt2;
+
+  /* Choose m and initiate mpone */
+  m = mp[p];  mpone.e = 1;  mpone.d[0]=mpone.d[1]=ONE;
+
+  /* Perform m newton iterations to solve for y: exp(y)-x=0.     */
+  /* The iterations formula is:  y(n+1)=y(n)+(x*exp(-y(n))-1).   */
+  cpy(y,&mpt1,p);
+  for (i=0; i<m; i++) {
+    mpt1.d[0]=-mpt1.d[0];
+    mpexp(&mpt1,&mpt2,p);
+    mul(x,&mpt2,&mpt1,p);
+    sub(&mpt1,&mpone,&mpt2,p);
+    add(y,&mpt2,&mpt1,p);
+    cpy(&mpt1,y,p);
+  }
+  return;
+}