Skip to content

Instantly share code, notes, and snippets.

@certik
Created May 27, 2011 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save certik/996210 to your computer and use it in GitHub Desktop.
Save certik/996210 to your computer and use it in GitHub Desktop.
sqrt(x) using Newton method
def sqrt(x):
eps = 1e-10
x = float(x)
r = x/2
residual = r**2 - x
while abs(residual) > eps:
r -= residual/(2*r)
residual = r**2 - x
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment