Compute logarithms using Java

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 0 Flares ×

This post is about calculating logarithms using Java. Java provides supports for logarithms via the java.lang.Math package, the log() function.This function is to the base e.Base e or the natural logarithm represent the log to a constant (e) whose value is approximately 2.718281828. To compute the logarithm you can use the code below

Now another question is how do you find the logarithm for other bases, example log to base 2 or log to base 10. This can be easily accomplished using the below property of logarithms.

Using this property we can change to any base. Let us take the example to understand this. How to find the log of 8 to the base 2.
log (8) to base 2 = log (8) base e / log (2) base e