Skip to content

Instantly share code, notes, and snippets.

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