Skip to content

Instantly share code, notes, and snippets.

@NullDev
Created September 8, 2022 19:08
Show Gist options
  • Save NullDev/6893491df96b14f428a401d933f5c0eb to your computer and use it in GitHub Desktop.
Save NullDev/6893491df96b14f428a401d933f5c0eb to your computer and use it in GitHub Desktop.
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