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

I have seen both Log10(x)

and Log(x)/Log(10)

used in different programs to calculate the logarithm of base 10. Is there anything in their implementation that makes using two natural logarithms more or equivalently performed than choosing one logarithm based on 10? The second seems wasteful if the desired base is known at compile time.

+3


source to share


1 answer


You should just use log10

one that actually calls your own function call (i.e. not implemented in Java - see StrictMath.log10

). log(x)/log(10)

is probably used by people who don't know about log10

. You will almost certainly not notice a performance mismatch between the two.



log10(x)

communicates your intent clearly, whereas it is log(x)/log(10)

not so clear that you really want the base 10 logarithm.

+5


source







All Articles