Created
September 8, 2022 19:08
-
-
Save NullDev/6893491df96b14f428a401d933f5c0eb 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
function sq(A){ | |
let B = A / 2; | |
let p = 0; | |
let i = 0; | |
for (;;){ | |
++i; | |
B = A / B + B; | |
B = B / 2; | |
if (p == B){ | |
console.log("Took " + i + " iterations."); | |
return B; | |
} | |
p = B; | |
} | |
} | |
console.log("C_SOL", sq(2500)); | |
console.log("M_SOL", Math.sqrt(2500)); | |
console.log("C_SOL", sq(9297482682382.872753537)); | |
console.log("M_SOL", Math.sqrt(9297482682382.872753537)); | |
console.log("C_SOL", sq(1)); | |
console.log("M_SOL", Math.sqrt(1)); | |
console.log("C_SOL", sq(0)); | |
console.log("M_SOL", Math.sqrt(0)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment