Created
February 11, 2024 19:01
-
-
Save mb6ockatf/059d9cfc43a3fa2ad22c846a0526b8cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/julia | |
const eps = 1e-40; | |
function log_2(n::Int64) | |
x = 1; | |
previous = 0; | |
while abs(2 ^ x - n) > eps | |
println(x); | |
x = (x + n / x) / 2; | |
if x != previous | |
previous = x; | |
else | |
break; | |
end | |
end | |
return x; | |
end | |
println(log_2(256)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment