- #1
AndersHermansson
- 61
- 0
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).
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).