Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java, is there a performance difference between Log and Log10?

Tags:

java

I have seen both Log10(x) and Log(x)/Log(10) used in different programs to calculate a base 10 logarithm. Is there anything about their implementation that makes taking two natural logarithms more or equivalently performant than taking a single base 10 logarithm? The second seems wasteful, provided the desired base is known at compile time.

like image 212
TBridges42 Avatar asked Jul 02 '15 17:07

TBridges42


People also ask

What is the difference between log and log10?

A common logarithm, Log10(), uses 10 as the base and a natural logarithm, Log(), uses the number e (approximately 2.71828) as the base.

Is log2 faster than log?

In contrast, for single precision, both functions log and log2 are the same apart from division by ln2 in the log2 case, hence the same speed.

Is log the same as log base 10?

So, when you see log by itself, it means base ten log.

Why do we use log10?

In statistics, log base 10 (log10) can be used to transform data for the following reasons: To make positively skewed data more "normal" To account for curvature in a linear model. To stabilize variation within groups.


1 Answers

You should just use log10, which actually ends up calling a native function (i.e. it is not implemented in Java -- see StrictMath.log10). log(x)/log(10) is likely used by people who don't know about log10. You almost certainly will not notice a performance discrepancy between the two variants.

log10(x) clearly conveys your intention, whereas with log(x)/log(10), it isn't as clear that you really want a base-10 logarithm.

like image 175
arshajii Avatar answered Sep 16 '22 19:09

arshajii