I want to find the log base 10 of a number. The way to convert from log base e to log base 10 is : log(n) = ln(n)/ln(10). Since java.lang.Math.log(n) is base e, I wrote these statements: x=Math.log(5/2)/Math.log(10) //result = 0.301029996 y=Math.log(5/1)/Math.log(10) //result = 0.69897 But my calculator gives 0.39794 for log(5/2) and 0.69897 for log(5/1). Why is it working for some numbers and not for others? [ March 13, 2003: Message edited by: Anita Raj ]

are x and y double values or are they int values? It seems like you have them set up as double values since you are getting a decimal point value.

Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233

posted

0

my bad, it looks like it might be your n variable. Double or int?

Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233

posted

0

You have: log(n) = ln(n)/ln(10). try log(n)=log(n)/log(10) I know that when you are using base e you don't need to use log, but rather use the natural log. For example, to convert from base e to base 10, we would say: log[e]x log[10]x = ---------- log[e]10

dunno bro, give it a try.

Anita Raj
Greenhorn

Joined: Mar 02, 2003
Posts: 7

posted

0

Yes, you guys are right. I should declare n as double. double n=5/2; double x=Math.log(n)/Math.log(10);

Not quite: double n = 5.0 / 2 is what you would need. double n = 5 / 2 would give n a value of 2.0 ; Or double n = ((double)5) / 2 ; or double n = 5 / ( (double)2 ); or double n = 5 / 2.0 ; Why? Because 5 / 2 is "only" 2. Maybe plain double n = 2.5 would do you too. Suppose you have: int top , bottom ; top = 5 ; bottom = 2 ; Then double n = ( (double)top ) / bottom ; would do the trick. [ March 14, 2003: Message edited by: Barry Gaunt ]

B. you love that phrase dont you? "That should do the trick." Thanks for the info anyway btw, do I get a ranch hand pin or something???

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729

posted

0

Steve said:

B. you love that phrase dont you? "That should do the trick."

Sort of. I caught it from one of my University professors who was always saying it at the end of proofs in Topology and Analysis lectures. It was "cooler" than QED in those days.