Created
May 27, 2011 21:26
-
-
Save certik/996213 to your computer and use it in GitHub Desktop.
sqrt(a**2+b**2) using Newton method and integers
This file contains hidden or 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
| 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