1989-05-10 16:08:14 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
|
|
|
/* $Header$ */
|
|
|
|
|
|
|
|
#include <math.h>
|
1991-03-19 16:39:40 +00:00
|
|
|
#include <float.h>
|
1989-12-18 15:44:36 +00:00
|
|
|
#include <errno.h>
|
1989-05-10 16:08:14 +00:00
|
|
|
#include "localmath.h"
|
|
|
|
|
|
|
|
double
|
|
|
|
log(double x)
|
|
|
|
{
|
1989-12-18 15:44:36 +00:00
|
|
|
/* Algorithm and coefficients from:
|
|
|
|
"Software manual for the elementary functions"
|
|
|
|
by W.J. Cody and W. Waite, Prentice-Hall, 1980
|
1989-05-10 16:08:14 +00:00
|
|
|
*/
|
1989-12-18 15:44:36 +00:00
|
|
|
static double a[] = {
|
|
|
|
-0.64124943423745581147e2,
|
|
|
|
0.16383943563021534222e2,
|
|
|
|
-0.78956112887491257267e0
|
1989-05-10 16:08:14 +00:00
|
|
|
};
|
1989-12-18 15:44:36 +00:00
|
|
|
static double b[] = {
|
|
|
|
-0.76949932108494879777e3,
|
|
|
|
0.31203222091924532844e3,
|
|
|
|
-0.35667977739034646171e2,
|
|
|
|
1.0
|
1989-05-10 16:08:14 +00:00
|
|
|
};
|
|
|
|
|
1989-12-18 15:44:36 +00:00
|
|
|
double znum, zden, z, w;
|
|
|
|
int exponent;
|
1989-05-10 16:08:14 +00:00
|
|
|
|
1991-03-19 16:39:40 +00:00
|
|
|
if (__IsNan(x)) {
|
|
|
|
errno = EDOM;
|
|
|
|
return x;
|
|
|
|
}
|
1989-12-18 15:44:36 +00:00
|
|
|
if (x < 0) {
|
1989-05-10 16:08:14 +00:00
|
|
|
errno = EDOM;
|
1989-12-18 15:44:36 +00:00
|
|
|
return -HUGE_VAL;
|
|
|
|
}
|
|
|
|
else if (x == 0) {
|
|
|
|
errno = ERANGE;
|
|
|
|
return -HUGE_VAL;
|
1989-05-10 16:08:14 +00:00
|
|
|
}
|
|
|
|
|
1991-03-19 16:39:40 +00:00
|
|
|
if (x <= DBL_MAX) {
|
|
|
|
}
|
|
|
|
else return x; /* for infinity and Nan */
|
1989-05-10 16:08:14 +00:00
|
|
|
x = frexp(x, &exponent);
|
1989-12-18 15:44:36 +00:00
|
|
|
if (x > M_1_SQRT2) {
|
|
|
|
znum = (x - 0.5) - 0.5;
|
|
|
|
zden = x * 0.5 + 0.5;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
znum = x - 0.5;
|
|
|
|
zden = znum * 0.5 + 0.5;
|
1989-05-10 16:08:14 +00:00
|
|
|
exponent--;
|
|
|
|
}
|
1989-12-18 15:44:36 +00:00
|
|
|
z = znum/zden; w = z * z;
|
|
|
|
x = z + z * w * (POLYNOM2(w,a)/POLYNOM3(w,b));
|
|
|
|
z = exponent;
|
|
|
|
x += z * (-2.121944400546905827679e-4);
|
|
|
|
return x + z * 0.693359375;
|
1989-05-10 16:08:14 +00:00
|
|
|
}
|