ack/lang/pc/libpc/log.c

66 lines
1.1 KiB
C
Raw Normal View History

1984-07-20 10:44:57 +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
*/
1984-07-20 10:44:57 +00:00
1994-06-24 14:02:31 +00:00
/* $Id$ */
1989-06-19 16:22:23 +00:00
1988-07-25 11:40:57 +00:00
#define __NO_DEFS
#include <math.h>
2018-06-17 20:30:27 +00:00
#include "pc.h"
1984-07-20 10:44:57 +00:00
1990-11-06 13:02:55 +00:00
#if __STDC__
1991-03-20 11:30:35 +00:00
#include <float.h>
1990-11-06 13:02:55 +00:00
#endif
1991-03-20 11:30:35 +00:00
#undef HUGE
2018-06-17 14:11:29 +00:00
#define HUGE 1e1000
1990-11-06 13:02:55 +00:00
2018-06-17 20:30:27 +00:00
double _log(double x)
1984-07-20 10:44:57 +00:00
{
1989-06-19 16:22:23 +00:00
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
by W.J. Cody and W. Waite, Prentice-Hall, 1980
1984-07-20 10:44:57 +00:00
*/
1989-06-19 16:22:23 +00:00
static double a[] = {
-0.64124943423745581147e2,
2018-06-17 14:11:29 +00:00
0.16383943563021534222e2,
1989-06-19 16:22:23 +00:00
-0.78956112887491257267e0
};
1989-06-19 16:22:23 +00:00
static double b[] = {
-0.76949932108494879777e3,
2018-06-17 14:11:29 +00:00
0.31203222091924532844e3,
1989-06-19 16:22:23 +00:00
-0.35667977739034646171e2,
2018-06-17 14:11:29 +00:00
1.0
};
2018-06-17 14:11:29 +00:00
double znum, zden, z, w;
int exponent;
2018-06-17 14:11:29 +00:00
if (x <= 0)
{
_trp(ELOG);
return -HUGE;
1984-07-20 10:44:57 +00:00
}
x = _fef(x, &exponent);
2018-06-17 14:11:29 +00:00
if (x > M_1_SQRT2)
{
1989-06-19 16:22:23 +00:00
znum = (x - 0.5) - 0.5;
zden = x * 0.5 + 0.5;
}
2018-06-17 14:11:29 +00:00
else
{
1989-06-19 16:22:23 +00:00
znum = x - 0.5;
zden = znum * 0.5 + 0.5;
exponent--;
}
2018-06-17 14:11:29 +00:00
z = znum / zden;
w = z * z;
x = z + z * w * (POLYNOM2(w, a) / POLYNOM3(w, b));
1989-06-19 16:22:23 +00:00
z = exponent;
x += z * (-2.121944400546905827679e-4);
return x + z * 0.693359375;
1984-07-20 10:44:57 +00:00
}