- #1
Arnoldjavs3
- 191
- 3
Homework Statement
I found this algorithm online for computing ln(x). I use the babylonians method for computing square root if it is relevant.
Code:
fun naturalLog(desired: Double): Double {
var naturalLog = desired // desired = x
for(number in 0..9) {
naturalLog = squareRootx(naturalLog) // squareroot 10 times
}
naturalLog -= 1
naturalLog *= 1024
return naturalLog
}
Homework Equations
The Attempt at a Solution
I just really don't understand. I've verified that it has accuracy of up to 2 decimal points.
When I compute ##ln(9)## I get ##2.19958358##, so after the 2nd decimal point it loses accuracy. It might be relevant to my squareroot algorithm, but I doubt it. What is this 1024 number? Is there some coincidence between a KiB = 1024 bytes? Googling around for ln(x) algorithms doesn't help.