Jump to content

how can i increase by poing


alzami

Recommended Posts

in my previous post i posted a problem about my javascript calculator .in my calculator in made a log button which base is 10;it shows a perfect integer result.say it gives accurately 2 if i want to find the log of 100.but if i want log of 104 it doesn't work;how can i solve that

function log10(el){	var m=document.getElementById(el);		for(;{         var d=Math.pow(10,i);				 if(d==m.value){			 m.value=i;			 i=0;			 break;		 }		  i++;	}}	
Link to comment
Share on other sites

If I remember correctly, you can get the base 10 logarithm out of the natural logarithm by dividing by the logarithm of the base:

function log10(n) {    return Math.log(n)/Math.LN10; //Math.LN10 is the logarithm of 10.}

You can also generalize the function:

function log(n,base) {    return Math.log(n)/Math.log(base);}
Link to comment
Share on other sites

The functions I just gave you solve those equations.

function log10(n) {    return Math.log(n)/Math.LN10; //Math.LN10 is the logarithm of 10.}alert(log10(104)); // Outputs 2.0170333392987803
Link to comment
Share on other sites

Math.log(n)/Math.LN10;

is it a complete statement.or it meant i can use Math.log or Math.LN10?i have never encountered such kind of statement.

if u see my calculator codes i already used Math.log. it says Math.log is an e based logarithm which is different frm 10 based logarithm

Edited by alzami
Link to comment
Share on other sites

It's a division, which I explained in a previous post.

you can get the base 10 logarithm out of the natural logarithm by dividing by the logarithm of the base

 

If you understand the properties of the logarithm you can obtain this expression.

 

ln(10^N) = N*ln(10)

therefore:

ln(10^N) / ln(10) = N * ln(10)/ln(10) = N

  • Like 1
Link to comment
Share on other sites

I've recently used a formula to calculate in log base 10, and you do need to be wary of rounding errors when diving one log by another. for example:

 

log2(100) / log2(10) == log10 (100) == 2

 

however in javascript Math.log(100) / Math.log(10) will equal something like 1.99999999...due to those floating-point rounding errors. something to be mindful of

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...