Skip to content

Commit

Permalink
Improved instantiation from strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
GDeLaurentis committed Mar 23, 2024
1 parent 1b85771 commit 557474c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyadic/finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def __init__(self, n, p=None):
self.p = n.p ** n.k
elif p is None and isinstance(n, str):
self.n, self.p = self.__rstr__(n)
elif isinstance(n, str) and n.isnumeric():
self.n, self.p = int(n), p
elif isinstance(n, str) and (n.isnumeric() or n.lstrip("+-").isnumeric()):
self.n, self.p = int(n) % int(p), p
else:
raise TypeError('Bad finite field constructor, (n, p) of value:({}, {}) and type:({}, {}).'.format(n, p, type(n), type(p)))

Expand Down
2 changes: 2 additions & 0 deletions tests/test_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def test_same_class_instantiation_and_unary_plus():
def test_instantiation_from_padic():
assert ModP(PAdic(123, 2 ** 31 - 19, 3)) == ModP(123, (2 ** 31 - 19) ** 3)

def test_instantiation_from_string():
assert ModP('+123', 2 ** 31 - 1) == ModP('-2147483524', 2 ** 31 - 1) == ModP(123, 2 ** 31 - 1)

def test_instantiation_with_complex():
p = 2 ** 31 - 19
Expand Down

0 comments on commit 557474c

Please sign in to comment.