RosettaCodeData/Task/Pathological-floating-point-problems/Python/pathological-floating-point-problems-1.py

13 lines
378 B
Python
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
from fractions import Fraction
def muller_seq(n:int) -> float:
seq = [Fraction(0), Fraction(2), Fraction(-4)]
for i in range(3, n+1):
next_value = (111 - 1130/seq[i-1]
+ 3000/(seq[i-1]*seq[i-2]))
seq.append(next_value)
return float(seq[n])
for n in [3, 4, 5, 6, 7, 8, 20, 30, 50, 100]:
print("{:4d} -> {}".format(n, muller_seq(n)))