Created
January 14, 2021 08:12
-
-
Save jakiki6/62b8bf21688104e4473f0a20939b2403 to your computer and use it in GitHub Desktop.
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 sqrt(x, b=2): | |
if x < 0: | |
x = abs(x) | |
img = True | |
else: | |
img = False | |
i = 0 | |
r = x | |
lr = 0 | |
while True: | |
i += 1 | |
lr = r | |
r = (((b - 1) * r) + x / (r ** (b - 1))) / b | |
if lr == r: | |
break | |
if img: | |
r = r * 1j | |
return r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment