log.c

Go to the documentation of this file.
00001 /*
00002  * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
00003  * See the copyright notice in the ACK home directory, in the file "Copyright".
00004  *
00005  * Author: Ceriel J.H. Jacobs
00006  */
00007 /* $Header: /opt/proj/minix/cvsroot/src/lib/math/log.c,v 1.1.1.1 2005/04/21 14:56:26 beng Exp $ */
00008 
00009 #include        <math.h>
00010 #include        <float.h>
00011 #include        <errno.h>
00012 #include        "localmath.h"
00013 
00014 double
00015 log(double x)
00016 {
00017         /*      Algorithm and coefficients from:
00018                         "Software manual for the elementary functions"
00019                         by W.J. Cody and W. Waite, Prentice-Hall, 1980
00020         */
00021         static double a[] = {
00022                 -0.64124943423745581147e2,
00023                  0.16383943563021534222e2,
00024                 -0.78956112887491257267e0
00025         };
00026         static double b[] = {
00027                 -0.76949932108494879777e3,
00028                  0.31203222091924532844e3,
00029                 -0.35667977739034646171e2,
00030                  1.0
00031         };
00032 
00033         double  znum, zden, z, w;
00034         int     exponent;
00035 
00036         if (__IsNan(x)) {
00037                 errno = EDOM;
00038                 return x;
00039         }
00040         if (x < 0) {
00041                 errno = EDOM;
00042                 return -HUGE_VAL;
00043         }
00044         else if (x == 0) {
00045                 errno = ERANGE;
00046                 return -HUGE_VAL;
00047         }
00048 
00049         if (x <= DBL_MAX) {
00050         }
00051         else return x;  /* for infinity and Nan */
00052         x = frexp(x, &exponent);
00053         if (x > M_1_SQRT2) {
00054                 znum = (x - 0.5) - 0.5;
00055                 zden = x * 0.5 + 0.5;
00056         }
00057         else {
00058                 znum = x - 0.5;
00059                 zden = znum * 0.5 + 0.5;
00060                 exponent--;
00061         }
00062         z = znum/zden; w = z * z;
00063         x = z + z * w * (POLYNOM2(w,a)/POLYNOM3(w,b));
00064         z = exponent;
00065         x += z * (-2.121944400546905827679e-4);
00066         return x + z * 0.693359375;
00067 }

Generated on Fri Apr 14 22:57:02 2006 for minix by  doxygen 1.4.6