Skip to content

Instantly share code, notes, and snippets.

@Highstaker
Created October 18, 2016 12:42
Show Gist options
  • Save Highstaker/20371d659a96a17237038e6242638a75 to your computer and use it in GitHub Desktop.
Save Highstaker/20371d659a96a17237038e6242638a75 to your computer and use it in GitHub Desktop.
from sys import argv
IN = float(argv[1])
PRECISION = 0.000000001
if IN == 1:
i = 1
elif IN > 1:
i = IN/2
size = i
sq = i**2
while abs(sq-IN)>PRECISION:
# print(i)#debug
size/=2
if sq > IN:
i= i - size
else:
i= i + size
sq = i**2
else:
size = (1 - IN)/2
i = IN + size
sq = i**2
while abs(sq-IN)>PRECISION:
# print(i)#debug
# __import__("time").sleep(1)
size/=2
if sq > IN:
i= i - size
else:
i= i + size
sq = i**2
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment