Skip to content

Instantly share code, notes, and snippets.

@jakiki6
Created January 14, 2021 08:12
Show Gist options
  • Save jakiki6/62b8bf21688104e4473f0a20939b2403 to your computer and use it in GitHub Desktop.
Save jakiki6/62b8bf21688104e4473f0a20939b2403 to your computer and use it in GitHub Desktop.
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