Computational-Analysis/chapter-03/dedekint/main.py
Jan-Niclas Loosen 26118be87f optimize ux
2025-04-17 18:08:18 +02:00

26 lines
461 B
Python

from dedekint import REAL
# mpq for rational numbers
from gmpy2 import mpq
def sqrt_two(q):
if q <= 0 or q * q < 2: return True
return False
x = REAL(sqrt_two)
print("1.41422 is smaller:", x.smaller(mpq(141422, 100000)))
print("1.41421 is smaller:", x.smaller(mpq(141421, 100000)))
k = 0
n = 1
z = 0
for k in range(100):
if x.smaller(mpq(z, n)):
z = z + 1
else:
print(z, "/", n)
z = (z - 1) * 10
n = n * 10