Skip to content

Instantly share code, notes, and snippets.

@tatarize
Created December 24, 2018 20:48
Show Gist options
  • Save tatarize/430cca6708a512f17cf0a8d674ca3d41 to your computer and use it in GitHub Desktop.
Save tatarize/430cca6708a512f17cf0a8d674ca3d41 to your computer and use it in GitHub Desktop.
import math
value = math.pi * 2
best = 1e-5
for i in range(1, 1000000):
fraction = float(i) / 12
numer = round(value * fraction)
v = numer / float(fraction)
err = v - value
if abs(err) < best:
print(str(numer) + "/" + str(float(i)) + "=" + str(v) + " @ " + str(err))
best = abs(err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment