Skip to content

Commit

Permalink
Switched integer type from unsigned to signed (i.e. np.uint64 -> np.i…
Browse files Browse the repository at this point in the history
…nt64) to support negative reals
  • Loading branch information
timbernat committed May 17, 2024
1 parent 3530819 commit 5c21eed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions polymerist/maths/fractions/continued.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


# CONSTANT PARAMETERS SHARED AMONGST MANY FUNCTIONS BELOW
INT_TYPE : Type = np.uint64
INT_TYPE : Type = np.int64
EPS = 1E-8
TOL = 1E-6

Expand Down Expand Up @@ -46,9 +46,9 @@ def continued_fraction_to_continuants(coeffs : Iterator[int]) -> Generator[tuple
def rational_approxes(x : Real, tol : float=TOL, eps : float=EPS) -> Generator[tuple[int, int], None, None]:
'''Unfold a real number into its continued fraction representation, then generate successive continuants of it'''
for p, q in continued_fraction_to_continuants(real_to_continued_fraction_coeffs(x, eps=eps)):
yield p, q
if abs(p/q - x) < tol:
break
yield p, q

def best_rational_approx(x : Real, tol : float=TOL, eps : float=EPS) -> tuple[int, int]:
'''Provide a rational approximation to a value with the smallest denominator that is within some tolerance'''
Expand Down

0 comments on commit 5c21eed

Please sign in to comment.