Ln(x) algorithm

  • #1
I was fiddling around with C++ and iterations and I found an algorithm for computing ln(x).


n = any number, the higher, the better the approximation
ln_x = 0;
divisor = 10^n;

while ( divisor <= x*10^n ) // Where x is the ln(x) you want to find.
{

ln_x += 1 / divisor;
divisor++;

}

What it does is add all integer fractions from 1/10^n to 1/x*10^(n+1).
 

Answers and Replies

  • #2
chroot
Staff Emeritus
Science Advisor
Gold Member
10,226
34
You've discovered the fact that [inte](1/x) dx is ln(x). Congratulations!

- Warren
 
  • #3
Thanks :)
 

Related Threads on Ln(x) algorithm

Replies
7
Views
11K
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
6
Views
7K
  • Last Post
Replies
1
Views
2K
  • Poll
  • Last Post
Replies
17
Views
5K
Replies
2
Views
983
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
9
Views
3K
  • Last Post
Replies
9
Views
758
  • Last Post
Replies
17
Views
1K
Top