Created
October 18, 2016 12:42
-
-
Save Highstaker/20371d659a96a17237038e6242638a75 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
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