Skip to content

Instantly share code, notes, and snippets.

@certik
Created May 27, 2011 21:26
Show Gist options
  • Select an option

  • Save certik/996213 to your computer and use it in GitHub Desktop.

Select an option

Save certik/996213 to your computer and use it in GitHub Desktop.
sqrt(a**2+b**2) using Newton method and integers
def prep2(a, b):
x = a**2 + b**2
r = x/2
residual = r**2 - x
r_old = r+1
while 1:
r -= residual/(2*r)
residual = r**2 - x
if r == r_old:
break
r_old = r
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment