• Post Reply Bookmark Topic Watch Topic
  • New Topic

natural logarithms (ln)  RSS feed

 
Tom Clement
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, working on a project which must calculate natural logarithms,
I see calculators do it all over, but my luck with source code evaluation hasn't turned up what I need.

Example:
ln 27 = 3.29583686600432907418573571076758

Can anyone help? Thanks, Tom
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume the standard java.lang.Math doesn't give you enough precision?

There are arbitrary precision libraries out there that will be able to do this for you. I can't think off the top of my head, but google will help you
 
Tom Clement
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, BigDecimal does the trick wrt precision, I'm looking for a possible
code snippet to help me get on track. I'm guessing Math.E and the log method will be involved, but honestly, math is about my weakest area, gui's and animation I'm much better at. Thanks, Tom
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the javadoc for Math.log()?

The log of a number 'x' in a base 'c' given the log in a base 'b' can be computed using:


Assuming we don't know the base of Math.log(), we could remove it from the equation as an unknown and always compute:


Maybe the question is already answered, but I did something similar he other day and decided to share

Dave

[EDIT - hmm, no sub scripts. Oh well, you get the picture.]
[ February 27, 2005: Message edited by: David O'Meara ]
 
Tom Clement
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I'll try it out in the morning...Tom
 
Tom Clement
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried it, and it worked, thank you very very much!

Math.log(x)/Math.log(10); was just what I needed, thanks again Tom
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!