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.
A common logarithm, Log10(), uses 10 as the base and a natural logarithm, Log(), uses the number e (approximately 2.71828) as the base.
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.
So, when you see log by itself, it means base ten log.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With