Created
January 18, 2017 07:22
-
-
Save sghall/6ced6002e2fa3e442c08691c8d03142d to your computer and use it in GitHub Desktop.
Manual Square Root in JavaScript
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 sqrt(num, guess) { | |
guess = guess || num / 3; | |
if (Math.abs(num - guess * guess) < 5e-15) { | |
return guess; | |
} else { | |
return sqrt(num, (num / guess + guess) / 2); | |
} | |
}; | |
console.log(sqrt(25)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment