Search code examples
javaandroidlogarithm

Using Math.log in Android


I'm trying to do the calculation of this formula,

i = (495 / (1.0324 - 0.19077 * (Math.log(76.2 - 25.4)) + 0.15456 * (Math.log(170.18))) - 450);

Instead of giving the correct answer which is 20.6, its showing the wrong answer 9.59!

Then i discovered that the Math.log function is giving wrong output! How to calculate such kinda operation in Android?


Solution

  • I think you want to use the logarithm in base 10, the one you use returns the closest double approximation of the natural logarithm.

    So your expression should be :

    i = (495 / (1.0324 - 0.19077 * (Math.log10(76.2 - 25.4)) + 0.15456 * (Math.log10(170.18))) - 450);
    

    Output :

    20.630024173730078