Is there a quick implementation of the log1p function?

I want to have a quick log1p function for Java. Java has Math.log1p, but apparently this is too slow for my needs.

I found this code here for log1p:

http://golang.org/src/pkg/math/log1p.go

for the GO language.

Is it the same as in Java, or is it faster? (if I outweigh it in java). Does anyone know of another quick implementation of log1p?

Thanks.

+4
source share
1 answer

since log1p(x) = Math.log(x+1) , finding a natural logarithmic algorithm is enough for what you need.

Fast Natural Logarithm in Java

Here I found the following approximation, and not much information about it, except that it is called the “Borchardt algorithm”, and this is from the book “Dead Reconstruction: Computing Without Tools”. The approximation is not very good (some may say very bad ...), it gets worse, the greater the value. But approximation is also a monotonous, slowly increasing function, which is good enough for my use.

open static double log (double x) {return 6 * (x - 1) / (x + 1 + 4 * (Math.sqrt (x))); }

This approximation is 11.7 times faster than Math.log ().

See this site. Also, performance comparison for math libraries in java.

But maybe you need link to C ++ compiled material, detailed here .

0
source

Source: https://habr.com/ru/post/1384172/


All Articles