[Ecls-list] log(complex) inaccurate for some values
Juan Jose Garcia-Ripoll
jjgarcia at users.sourceforge.net
Mon Apr 14 08:06:14 UTC 2008
On Mon, Apr 14, 2008 at 2:37 AM, Raymond Toy <toy.raymond at gmail.com> wrote:
> Here's an outline for a one possible implementation of log1p. Very likely
> not as optimized as the C version, but should work with reasonable accuracy.
Hi, looks nice. The version I found around, and which only activates
when the C library does not support log1p (Windows, probably) is one I
found googling around, and which compensates the errors in the
ordinary logarithm.
double log1p(double x)
{
double u = 1.0 + x;
if (u == 1) {
return 0.0;
} else {
return (log(u) * x)/(u - 1.0);
}
}
But your implementation seems more stable. The only thing that looks
expensive is the step for making "x" small. Wouldn't it suffice to use
log1p(x) = series if |x| <= 1, and log1p(x) = log1p(1/x) + log(x)
elsewhere?
Juanjo
--
Facultad de Fisicas, Universidad Complutense,
Ciudad Universitaria s/n Madrid 28040 (Spain)
http://juanjose.garciaripoll.googlepages.com
More information about the ecl-devel
mailing list