[Ecls-list] log(complex) inaccurate for some values

Raymond Toy toy.raymond at gmail.com
Mon Apr 14 00:37:19 UTC 2008

Juan Jose Garcia-Ripoll wrote:
> On Sun, Apr 13, 2008 at 4:03 PM, Raymond Toy <toy.raymond at gmail.com> wrote:
>>  But don't use the log function to evaluate this.  Use log1p(z) =
>>  log(1+z).  Most C libraries have a log1p function already, but if not,
>>  you can just use the series formula since z is small.
> Thanks Ray. I did not know about the log1p function. I have changed
> ECL to support and export it as a lisp function, adding a simplistic
> implementation for the platforms that do not support it (mingw32 I
> believe). Now
My pleasure.

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.

log1p(x) = 2*log1p(x/(1+sqrt(1+x)))

This makes x progressively smaller.  When x is small enough, you can use 
the series

log1p(x) = 2*sum((x/(2+x))^(2*k+1)/(2*k+1)) for k from 0 to inf.

This series converges quite fast, even for x as large as 1.

Hope this helps a bit,


More information about the ecl-devel mailing list