Skip to content

Commit d84d8d2

Browse files
committed
Recommend use of attribute for large moduli; update dependency version.
1 parent 8dd1dcc commit d84d8d2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ authors = [
1313
readme = "README.rst"
1414
requires-python = ">=3.7"
1515
dependencies = [
16-
"egcd~=1.0"
16+
"egcd~=2.0"
1717
]
1818

1919
[project.urls]

src/modulo/modulo.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,22 @@ def __len__(self: modulo) -> int:
10501050
4
10511051
10521052
Use of the built-in :obj:`len` function is the recommended approach
1053-
for retrieving the ``modulus`` attribute of a :obj:`modulo` instance.
1053+
for retrieving the ``modulus`` attribute of a :obj:`modulo` instance
1054+
when the modulus is small. However, this will not work when the
1055+
modulus is ``2 ** 63`` or greater.
1056+
1057+
>>> len(mod(2 ** 63 - 1))
1058+
9223372036854775807
1059+
>>> len(mod(2 ** 63))
1060+
Traceback (most recent call last):
1061+
...
1062+
OverflowError: cannot fit 'int' into an index-sized integer
1063+
1064+
In such cases, the recommended approach is to leverage the
1065+
``modulus`` attribute.
1066+
1067+
>>> mod(2 ** 63).modulus
1068+
9223372036854775808
10541069
"""
10551070
return self.modulus
10561071

0 commit comments

Comments
 (0)