Skip to content

Instantly share code, notes, and snippets.

@marciol
Created July 27, 2012 22:36
Show Gist options
  • Save marciol/3190787 to your computer and use it in GitHub Desktop.
Save marciol/3190787 to your computer and use it in GitHub Desktop.
let newtonSqrt x =
let accuracy = 0.00001 // desired accuracy
let rec iterate a =
let diff = x - a*a
if abs diff <= accuracy
then a
else iterate ((a + x/a) / 2.0)
iterate (x/2.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment