cfractions 2.2.0__tar.gz → 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cfractions-2.3.0/MANIFEST.in +3 -0
- {cfractions-2.2.0/cfractions.egg-info → cfractions-2.3.0}/PKG-INFO +36 -13
- {cfractions-2.2.0 → cfractions-2.3.0}/README.md +7 -7
- cfractions-2.3.0/cfractions/__init__.py +19 -0
- cfractions-2.3.0/cfractions/_fractions.py +438 -0
- {cfractions-2.2.0 → cfractions-2.3.0/cfractions.egg-info}/PKG-INFO +36 -13
- {cfractions-2.2.0 → cfractions-2.3.0}/cfractions.egg-info/SOURCES.txt +3 -1
- cfractions-2.3.0/cfractions.egg-info/requires.txt +5 -0
- cfractions-2.3.0/pyproject.toml +77 -0
- cfractions-2.3.0/setup.py +43 -0
- {cfractions-2.2.0 → cfractions-2.3.0}/src/cfractions.c +4 -5
- cfractions-2.2.0/MANIFEST.in +0 -1
- cfractions-2.2.0/cfractions/__init__.py +0 -203
- cfractions-2.2.0/cfractions/__init__.pyi +0 -266
- cfractions-2.2.0/setup.py +0 -50
- {cfractions-2.2.0 → cfractions-2.3.0}/LICENSE +0 -0
- {cfractions-2.2.0 → cfractions-2.3.0}/cfractions/py.typed +0 -0
- {cfractions-2.2.0 → cfractions-2.3.0}/cfractions.egg-info/dependency_links.txt +0 -0
- {cfractions-2.2.0 → cfractions-2.3.0}/cfractions.egg-info/not-zip-safe +0 -0
- {cfractions-2.2.0 → cfractions-2.3.0}/cfractions.egg-info/top_level.txt +0 -0
- {cfractions-2.2.0 → cfractions-2.3.0}/setup.cfg +0 -0
|
@@ -1,26 +1,49 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cfractions
|
|
3
|
-
Version: 2.
|
|
4
|
-
Summary: Python C API alternative to `fractions` module.
|
|
3
|
+
Version: 2.3.0
|
|
5
4
|
Home-page: https://github.com/lycantropos/cfractions/
|
|
6
5
|
Download-URL: https://github.com/lycantropos/cfractions/archive/master.zip
|
|
7
|
-
Author: Azat Ibrakov
|
|
8
|
-
Author-email: azatibrakov@gmail.com
|
|
6
|
+
Author-email: Azat Ibrakov <azatibrakov@gmail.com>
|
|
9
7
|
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2021 Azat Ibrakov
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
10
29
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
12
30
|
Classifier: Programming Language :: Python :: 3.8
|
|
13
31
|
Classifier: Programming Language :: Python :: 3.9
|
|
14
32
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
33
|
Classifier: Programming Language :: Python :: 3.11
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
35
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
17
36
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
18
|
-
Requires-Python: >=3.
|
|
37
|
+
Requires-Python: >=3.8
|
|
19
38
|
Description-Content-Type: text/markdown
|
|
20
39
|
License-File: LICENSE
|
|
40
|
+
Requires-Dist: typing-extensions>=4.11.0
|
|
41
|
+
Provides-Extra: tests
|
|
42
|
+
Requires-Dist: hypothesis<7.0,>=6.100.1; extra == "tests"
|
|
43
|
+
Requires-Dist: pytest<9.0,>=8.1.2; extra == "tests"
|
|
21
44
|
|
|
22
45
|
cfractions
|
|
23
|
-
|
|
46
|
+
========
|
|
24
47
|
|
|
25
48
|
[](https://github.com/lycantropos/cfractions/actions/workflows/ci.yml "Github Actions")
|
|
26
49
|
[](https://codecov.io/gh/lycantropos/cfractions "Codecov")
|
|
@@ -41,8 +64,8 @@ Main features are:
|
|
|
41
64
|
|
|
42
65
|
---
|
|
43
66
|
|
|
44
|
-
In what follows `python` is an alias for `python3.
|
|
45
|
-
or any later version (`python3.
|
|
67
|
+
In what follows `python` is an alias for `python3.8` or `pypy3.8`
|
|
68
|
+
or any later version (`python3.9`, `pypy3.9` and so on).
|
|
46
69
|
|
|
47
70
|
Installation
|
|
48
71
|
------------
|
|
@@ -69,7 +92,7 @@ cd cfractions
|
|
|
69
92
|
|
|
70
93
|
Install
|
|
71
94
|
```bash
|
|
72
|
-
python
|
|
95
|
+
python -m pip install -e .
|
|
73
96
|
```
|
|
74
97
|
|
|
75
98
|
Usage
|
|
@@ -131,7 +154,7 @@ Bump version
|
|
|
131
154
|
bump2version --verbose $CATEGORY
|
|
132
155
|
```
|
|
133
156
|
|
|
134
|
-
This will set version to `major.minor.patch-alpha`.
|
|
157
|
+
This will set version to `major.minor.patch-alpha`.
|
|
135
158
|
|
|
136
159
|
#### Release
|
|
137
160
|
|
|
@@ -149,9 +172,9 @@ This will set version to `major.minor.patch`.
|
|
|
149
172
|
|
|
150
173
|
### Running tests
|
|
151
174
|
|
|
152
|
-
Install dependencies
|
|
175
|
+
Install with dependencies
|
|
153
176
|
```bash
|
|
154
|
-
python -m pip install -
|
|
177
|
+
python -m pip install -e .[tests]
|
|
155
178
|
```
|
|
156
179
|
|
|
157
180
|
Plain
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
cfractions
|
|
2
|
-
|
|
2
|
+
========
|
|
3
3
|
|
|
4
4
|
[](https://github.com/lycantropos/cfractions/actions/workflows/ci.yml "Github Actions")
|
|
5
5
|
[](https://codecov.io/gh/lycantropos/cfractions "Codecov")
|
|
@@ -20,8 +20,8 @@ Main features are:
|
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
In what follows `python` is an alias for `python3.
|
|
24
|
-
or any later version (`python3.
|
|
23
|
+
In what follows `python` is an alias for `python3.8` or `pypy3.8`
|
|
24
|
+
or any later version (`python3.9`, `pypy3.9` and so on).
|
|
25
25
|
|
|
26
26
|
Installation
|
|
27
27
|
------------
|
|
@@ -48,7 +48,7 @@ cd cfractions
|
|
|
48
48
|
|
|
49
49
|
Install
|
|
50
50
|
```bash
|
|
51
|
-
python
|
|
51
|
+
python -m pip install -e .
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Usage
|
|
@@ -110,7 +110,7 @@ Bump version
|
|
|
110
110
|
bump2version --verbose $CATEGORY
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
This will set version to `major.minor.patch-alpha`.
|
|
113
|
+
This will set version to `major.minor.patch-alpha`.
|
|
114
114
|
|
|
115
115
|
#### Release
|
|
116
116
|
|
|
@@ -128,9 +128,9 @@ This will set version to `major.minor.patch`.
|
|
|
128
128
|
|
|
129
129
|
### Running tests
|
|
130
130
|
|
|
131
|
-
Install dependencies
|
|
131
|
+
Install with dependencies
|
|
132
132
|
```bash
|
|
133
|
-
python -m pip install -
|
|
133
|
+
python -m pip install -e .[tests]
|
|
134
134
|
```
|
|
135
135
|
|
|
136
136
|
Plain
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Python C API alternative to `fractions` module."""
|
|
2
|
+
|
|
3
|
+
import typing as _t
|
|
4
|
+
|
|
5
|
+
__version__ = '2.3.0'
|
|
6
|
+
|
|
7
|
+
if _t.TYPE_CHECKING:
|
|
8
|
+
from . import _fractions
|
|
9
|
+
|
|
10
|
+
Fraction = _fractions.Fraction
|
|
11
|
+
else:
|
|
12
|
+
try:
|
|
13
|
+
from . import _cfractions
|
|
14
|
+
except ImportError:
|
|
15
|
+
from . import _fractions
|
|
16
|
+
|
|
17
|
+
Fraction = _fractions.Fraction
|
|
18
|
+
else:
|
|
19
|
+
Fraction = _cfractions.Fraction
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import numbers as _numbers
|
|
4
|
+
import typing as _t
|
|
5
|
+
from fractions import Fraction as _Fraction
|
|
6
|
+
|
|
7
|
+
import typing_extensions as _te
|
|
8
|
+
|
|
9
|
+
_Rational = _t.Union[_Fraction, _numbers.Rational, int]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@_t.final
|
|
13
|
+
class Fraction(_numbers.Rational):
|
|
14
|
+
@property
|
|
15
|
+
def numerator(self, /) -> int:
|
|
16
|
+
return self._value.numerator
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def denominator(self, /) -> int:
|
|
20
|
+
return self._value.denominator
|
|
21
|
+
|
|
22
|
+
def as_integer_ratio(self, /) -> tuple[int, int]:
|
|
23
|
+
return self.numerator, self.denominator
|
|
24
|
+
|
|
25
|
+
def limit_denominator(self, max_denominator: int = 10**6, /) -> _te.Self:
|
|
26
|
+
return _to_fraction_if_std_fraction(
|
|
27
|
+
self._value.limit_denominator(max_denominator)
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
__module__ = 'cfractions'
|
|
31
|
+
__slots__ = ('_value',)
|
|
32
|
+
|
|
33
|
+
_value: _Fraction
|
|
34
|
+
|
|
35
|
+
def __init_subclass__(cls, /, **_kwargs: _t.Any) -> None:
|
|
36
|
+
raise TypeError(
|
|
37
|
+
"type 'cfractions.Fraction' is not an acceptable base type"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
@_t.overload
|
|
41
|
+
def __new__(
|
|
42
|
+
cls, value: _Rational | _te.Self | float | str = ..., _: None = ..., /
|
|
43
|
+
) -> _te.Self: ...
|
|
44
|
+
|
|
45
|
+
@_t.overload
|
|
46
|
+
def __new__(cls, numerator: int, denominator: int, /) -> _te.Self: ...
|
|
47
|
+
|
|
48
|
+
def __new__(
|
|
49
|
+
cls,
|
|
50
|
+
numerator: _Rational | _te.Self | float | str = 0,
|
|
51
|
+
denominator: int | None = None,
|
|
52
|
+
/,
|
|
53
|
+
) -> _te.Self:
|
|
54
|
+
if denominator is None:
|
|
55
|
+
value = (
|
|
56
|
+
_Fraction(int(numerator.numerator), int(numerator.denominator))
|
|
57
|
+
if isinstance(numerator, _numbers.Rational)
|
|
58
|
+
else _Fraction(numerator)
|
|
59
|
+
)
|
|
60
|
+
else:
|
|
61
|
+
if not isinstance(denominator, int):
|
|
62
|
+
raise TypeError('Denominator should be an integer.')
|
|
63
|
+
if not isinstance(numerator, int):
|
|
64
|
+
raise TypeError(
|
|
65
|
+
'Numerator should be an integer '
|
|
66
|
+
'when denominator is specified.'
|
|
67
|
+
)
|
|
68
|
+
value = _Fraction(numerator, denominator)
|
|
69
|
+
self = super().__new__(cls)
|
|
70
|
+
self._value = value
|
|
71
|
+
return self
|
|
72
|
+
|
|
73
|
+
def __abs__(self, /) -> _te.Self:
|
|
74
|
+
return Fraction(abs(self._value))
|
|
75
|
+
|
|
76
|
+
@_t.overload
|
|
77
|
+
def __add__(self, other: _Rational | _te.Self, /) -> _te.Self: ...
|
|
78
|
+
|
|
79
|
+
@_t.overload
|
|
80
|
+
def __add__(self, other: float, /) -> float: ...
|
|
81
|
+
|
|
82
|
+
@_t.overload
|
|
83
|
+
def __add__(self, other: _t.Any, /) -> _t.Any: ...
|
|
84
|
+
|
|
85
|
+
def __add__(self, other: _t.Any, /) -> _t.Any:
|
|
86
|
+
return _to_fraction_if_std_fraction(
|
|
87
|
+
self._value + _to_std_fraction_if_rational(other)
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
def __ceil__(self, /) -> int:
|
|
91
|
+
return self._value.__ceil__()
|
|
92
|
+
|
|
93
|
+
def __copy__(self, /) -> _te.Self:
|
|
94
|
+
return self
|
|
95
|
+
|
|
96
|
+
def __deepcopy__(
|
|
97
|
+
self, memo: dict[str, _t.Any] | None = None, /
|
|
98
|
+
) -> _te.Self:
|
|
99
|
+
return self
|
|
100
|
+
|
|
101
|
+
@_t.overload
|
|
102
|
+
def __divmod__(
|
|
103
|
+
self, divisor: _Rational | _te.Self, /
|
|
104
|
+
) -> tuple[int, _te.Self]: ...
|
|
105
|
+
|
|
106
|
+
@_t.overload
|
|
107
|
+
def __divmod__(self, divisor: float, /) -> tuple[float, float]: ...
|
|
108
|
+
|
|
109
|
+
@_t.overload
|
|
110
|
+
def __divmod__(self, divisor: _t.Any, /) -> _t.Any: ...
|
|
111
|
+
|
|
112
|
+
def __divmod__(self, divisor: _t.Any, /) -> _t.Any:
|
|
113
|
+
result = divmod(self._value, _to_std_fraction_if_rational(divisor))
|
|
114
|
+
return (
|
|
115
|
+
(result[0], Fraction(result[1]))
|
|
116
|
+
if isinstance(result, tuple) and isinstance(result[1], _Fraction)
|
|
117
|
+
else result
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
@_t.overload
|
|
121
|
+
def __eq__(self, other: _Rational | _te.Self | float, /) -> bool: ...
|
|
122
|
+
|
|
123
|
+
@_t.overload
|
|
124
|
+
def __eq__(self, other: _t.Any, /) -> _t.Any: ...
|
|
125
|
+
|
|
126
|
+
def __eq__(self, other: _t.Any, /) -> _t.Any:
|
|
127
|
+
return self._value == other
|
|
128
|
+
|
|
129
|
+
def __float__(self, /) -> float:
|
|
130
|
+
return float(self._value)
|
|
131
|
+
|
|
132
|
+
def __floor__(self, /) -> int:
|
|
133
|
+
return self._value.__floor__()
|
|
134
|
+
|
|
135
|
+
@_t.overload
|
|
136
|
+
def __floordiv__(self, divisor: _Rational | _te.Self, /) -> int: ...
|
|
137
|
+
|
|
138
|
+
@_t.overload
|
|
139
|
+
def __floordiv__(self, divisor: float, /) -> float: ...
|
|
140
|
+
|
|
141
|
+
@_t.overload
|
|
142
|
+
def __floordiv__(self, divisor: _t.Any, /) -> _t.Any: ...
|
|
143
|
+
|
|
144
|
+
def __floordiv__(self, divisor: _t.Any, /) -> _t.Any:
|
|
145
|
+
return self._value // _to_std_fraction_if_rational(divisor)
|
|
146
|
+
|
|
147
|
+
@_t.overload
|
|
148
|
+
def __ge__(self, other: _Rational | _te.Self, /) -> bool: ...
|
|
149
|
+
|
|
150
|
+
@_t.overload
|
|
151
|
+
def __ge__(self, other: float, /) -> bool: ...
|
|
152
|
+
|
|
153
|
+
@_t.overload
|
|
154
|
+
def __ge__(self, other: _t.Any, /) -> _t.Any: ...
|
|
155
|
+
|
|
156
|
+
def __ge__(self, other: _t.Any, /) -> _t.Any:
|
|
157
|
+
return self._value >= other
|
|
158
|
+
|
|
159
|
+
@_t.overload
|
|
160
|
+
def __gt__(self, other: _Rational | _te.Self, /) -> bool: ...
|
|
161
|
+
|
|
162
|
+
@_t.overload
|
|
163
|
+
def __gt__(self, other: float, /) -> bool: ...
|
|
164
|
+
|
|
165
|
+
@_t.overload
|
|
166
|
+
def __gt__(self, other: _t.Any, /) -> _t.Any: ...
|
|
167
|
+
|
|
168
|
+
def __gt__(self, other: _t.Any, /) -> _t.Any:
|
|
169
|
+
return self._value > other
|
|
170
|
+
|
|
171
|
+
def __hash__(self, /) -> int:
|
|
172
|
+
return hash(self._value)
|
|
173
|
+
|
|
174
|
+
@_t.overload
|
|
175
|
+
def __le__(self, other: _Rational | _te.Self, /) -> bool: ...
|
|
176
|
+
|
|
177
|
+
@_t.overload
|
|
178
|
+
def __le__(self, other: float, /) -> bool: ...
|
|
179
|
+
|
|
180
|
+
@_t.overload
|
|
181
|
+
def __le__(self, other: _t.Any, /) -> _t.Any: ...
|
|
182
|
+
|
|
183
|
+
def __le__(self, other: _t.Any, /) -> _t.Any:
|
|
184
|
+
return self._value <= other
|
|
185
|
+
|
|
186
|
+
@_t.overload
|
|
187
|
+
def __lt__(self, other: _Rational | _te.Self, /) -> bool: ...
|
|
188
|
+
|
|
189
|
+
@_t.overload
|
|
190
|
+
def __lt__(self, other: float, /) -> bool: ...
|
|
191
|
+
|
|
192
|
+
@_t.overload
|
|
193
|
+
def __lt__(self, other: _t.Any, /) -> _t.Any: ...
|
|
194
|
+
|
|
195
|
+
def __lt__(self, other: _t.Any, /) -> _t.Any:
|
|
196
|
+
return self._value < other
|
|
197
|
+
|
|
198
|
+
@_t.overload
|
|
199
|
+
def __mod__(self, divisor: _Rational | _te.Self, /) -> _te.Self: ...
|
|
200
|
+
|
|
201
|
+
@_t.overload
|
|
202
|
+
def __mod__(self, divisor: float, /) -> float: ...
|
|
203
|
+
|
|
204
|
+
@_t.overload
|
|
205
|
+
def __mod__(self, divisor: _t.Any, /) -> _t.Any: ...
|
|
206
|
+
|
|
207
|
+
def __mod__(self, divisor: _t.Any, /) -> _t.Any:
|
|
208
|
+
return _to_fraction_if_std_fraction(
|
|
209
|
+
self._value % _to_std_fraction_if_rational(divisor)
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
@_t.overload
|
|
213
|
+
def __mul__(self, other: _Rational | _te.Self, /) -> _te.Self: ...
|
|
214
|
+
|
|
215
|
+
@_t.overload
|
|
216
|
+
def __mul__(self, other: float, /) -> float: ...
|
|
217
|
+
|
|
218
|
+
@_t.overload
|
|
219
|
+
def __mul__(self, other: _t.Any, /) -> _t.Any: ...
|
|
220
|
+
|
|
221
|
+
def __mul__(self, other: _t.Any, /) -> _t.Any:
|
|
222
|
+
return _to_fraction_if_std_fraction(
|
|
223
|
+
self._value * _to_std_fraction_if_rational(other)
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
def __neg__(self, /) -> _te.Self:
|
|
227
|
+
return Fraction(-self._value)
|
|
228
|
+
|
|
229
|
+
def __pos__(self, /) -> _te.Self:
|
|
230
|
+
return Fraction(+self._value)
|
|
231
|
+
|
|
232
|
+
@_t.overload
|
|
233
|
+
def __pow__(self, exponent: int, /) -> _te.Self: ...
|
|
234
|
+
|
|
235
|
+
@_t.overload
|
|
236
|
+
def __pow__(
|
|
237
|
+
self, exponent: _Rational | _te.Self, /
|
|
238
|
+
) -> _te.Self | float: ...
|
|
239
|
+
|
|
240
|
+
@_t.overload
|
|
241
|
+
def __pow__(self, exponent: float, /) -> float: ...
|
|
242
|
+
|
|
243
|
+
@_t.overload
|
|
244
|
+
def __pow__(self, exponent: _t.Any, /) -> _t.Any: ...
|
|
245
|
+
|
|
246
|
+
def __pow__(self, exponent: _t.Any, /) -> _t.Any:
|
|
247
|
+
return _to_fraction_if_std_fraction(
|
|
248
|
+
self._value ** _to_std_fraction_if_rational(exponent)
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
@_t.overload
|
|
252
|
+
def __radd__(self, other: _Rational, /) -> _te.Self: ...
|
|
253
|
+
|
|
254
|
+
@_t.overload
|
|
255
|
+
def __radd__(self, other: float, /) -> float: ...
|
|
256
|
+
|
|
257
|
+
@_t.overload
|
|
258
|
+
def __radd__(self, other: _t.Any, /) -> _t.Any: ...
|
|
259
|
+
|
|
260
|
+
def __radd__(self, other: _t.Any, /) -> _t.Any:
|
|
261
|
+
return _to_fraction_if_std_fraction(
|
|
262
|
+
_to_std_fraction_if_rational(other) + self._value
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
@_t.overload
|
|
266
|
+
def __rdivmod__(self, dividend: _Rational, /) -> tuple[int, _te.Self]: ...
|
|
267
|
+
|
|
268
|
+
@_t.overload
|
|
269
|
+
def __rdivmod__(self, dividend: float, /) -> tuple[float, float]: ...
|
|
270
|
+
|
|
271
|
+
@_t.overload
|
|
272
|
+
def __rdivmod__(self, dividend: _t.Any, /) -> _t.Any: ...
|
|
273
|
+
|
|
274
|
+
def __rdivmod__(self, dividend: _t.Any, /) -> _t.Any:
|
|
275
|
+
result = divmod(_to_std_fraction_if_rational(dividend), self._value)
|
|
276
|
+
return (
|
|
277
|
+
(result[0], Fraction(result[1]))
|
|
278
|
+
if isinstance(result, tuple) and isinstance(result[1], _Fraction)
|
|
279
|
+
else result
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
def __repr__(self) -> str:
|
|
283
|
+
return self._value.__repr__()
|
|
284
|
+
|
|
285
|
+
@_t.overload
|
|
286
|
+
def __rfloordiv__(self, dividend: _Rational, /) -> int: ...
|
|
287
|
+
|
|
288
|
+
@_t.overload
|
|
289
|
+
def __rfloordiv__(self, dividend: float, /) -> float: ...
|
|
290
|
+
|
|
291
|
+
@_t.overload
|
|
292
|
+
def __rfloordiv__(self, dividend: _t.Any, /) -> _t.Any: ...
|
|
293
|
+
|
|
294
|
+
def __rfloordiv__(self, dividend: _t.Any, /) -> _t.Any:
|
|
295
|
+
return _to_std_fraction_if_rational(dividend) // self._value
|
|
296
|
+
|
|
297
|
+
@_t.overload
|
|
298
|
+
def __rmod__(self, dividend: _Rational, /) -> _te.Self: ...
|
|
299
|
+
|
|
300
|
+
@_t.overload
|
|
301
|
+
def __rmod__(self, dividend: float, /) -> float: ...
|
|
302
|
+
|
|
303
|
+
@_t.overload
|
|
304
|
+
def __rmod__(self, dividend: _t.Any, /) -> _t.Any: ...
|
|
305
|
+
|
|
306
|
+
def __rmod__(self, dividend: _t.Any, /) -> _t.Any:
|
|
307
|
+
return _to_fraction_if_std_fraction(dividend % self._value)
|
|
308
|
+
|
|
309
|
+
@_t.overload
|
|
310
|
+
def __rmul__(self, other: _Rational, /) -> _te.Self: ...
|
|
311
|
+
|
|
312
|
+
@_t.overload
|
|
313
|
+
def __rmul__(self, other: float, /) -> float: ...
|
|
314
|
+
|
|
315
|
+
@_t.overload
|
|
316
|
+
def __rmul__(self, other: _t.Any, /) -> _t.Any: ...
|
|
317
|
+
|
|
318
|
+
def __rmul__(self, other: _t.Any, /) -> _t.Any:
|
|
319
|
+
return _to_fraction_if_std_fraction(
|
|
320
|
+
_to_std_fraction_if_rational(other) * self._value
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
@_t.overload
|
|
324
|
+
def __round__(self, precision: None = ..., /) -> int: ...
|
|
325
|
+
|
|
326
|
+
@_t.overload
|
|
327
|
+
def __round__(self, precision: int, /) -> _te.Self: ...
|
|
328
|
+
|
|
329
|
+
def __round__(self, precision: int | None = None, /) -> int | _te.Self:
|
|
330
|
+
return _to_fraction_if_std_fraction(round(self._value, precision))
|
|
331
|
+
|
|
332
|
+
@_t.overload
|
|
333
|
+
def __rpow__(self, base: _Rational, /) -> _te.Self | float: ...
|
|
334
|
+
|
|
335
|
+
@_t.overload
|
|
336
|
+
def __rpow__(self, base: float, /) -> float: ...
|
|
337
|
+
|
|
338
|
+
@_t.overload
|
|
339
|
+
def __rpow__(self, base: _t.Any, /) -> _t.Any: ...
|
|
340
|
+
|
|
341
|
+
def __rpow__(self, base: _t.Any, /) -> _t.Any:
|
|
342
|
+
return _to_fraction_if_std_fraction(
|
|
343
|
+
_to_std_fraction_if_rational(base) ** self._value
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
@_t.overload
|
|
347
|
+
def __rsub__(self, minuend: _Rational, /) -> _te.Self: ...
|
|
348
|
+
|
|
349
|
+
@_t.overload
|
|
350
|
+
def __rsub__(self, minuend: float, /) -> float: ...
|
|
351
|
+
|
|
352
|
+
@_t.overload
|
|
353
|
+
def __rsub__(self, minuend: _t.Any, /) -> _t.Any: ...
|
|
354
|
+
|
|
355
|
+
def __rsub__(self, minuend: _t.Any, /) -> _t.Any:
|
|
356
|
+
return _to_fraction_if_std_fraction(
|
|
357
|
+
_to_std_fraction_if_rational(minuend) - self._value
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
@_t.overload
|
|
361
|
+
def __rtruediv__(self, dividend: _Rational, /) -> _te.Self: ...
|
|
362
|
+
|
|
363
|
+
@_t.overload
|
|
364
|
+
def __rtruediv__(self, dividend: float, /) -> float: ...
|
|
365
|
+
|
|
366
|
+
@_t.overload
|
|
367
|
+
def __rtruediv__(self, dividend: _t.Any, /) -> _t.Any: ...
|
|
368
|
+
|
|
369
|
+
def __rtruediv__(self, dividend: _t.Any, /) -> _t.Any:
|
|
370
|
+
return _to_fraction_if_std_fraction(
|
|
371
|
+
_to_std_fraction_if_rational(dividend) / self._value
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
def __str__(self) -> str:
|
|
375
|
+
return self._value.__str__()
|
|
376
|
+
|
|
377
|
+
@_t.overload
|
|
378
|
+
def __sub__(self, subtrahend: _Rational | _te.Self, /) -> _te.Self: ...
|
|
379
|
+
|
|
380
|
+
@_t.overload
|
|
381
|
+
def __sub__(self, subtrahend: float, /) -> float: ...
|
|
382
|
+
|
|
383
|
+
@_t.overload
|
|
384
|
+
def __sub__(self, subtrahend: _t.Any, /) -> _t.Any: ...
|
|
385
|
+
|
|
386
|
+
def __sub__(self, subtrahend: _t.Any, /) -> _t.Any:
|
|
387
|
+
return _to_fraction_if_std_fraction(
|
|
388
|
+
self._value - _to_std_fraction_if_rational(subtrahend)
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
@_t.overload
|
|
392
|
+
def __truediv__(self, divisor: _Rational | _te.Self, /) -> _te.Self: ...
|
|
393
|
+
|
|
394
|
+
@_t.overload
|
|
395
|
+
def __truediv__(self, divisor: float, /) -> float: ...
|
|
396
|
+
|
|
397
|
+
@_t.overload
|
|
398
|
+
def __truediv__(self, divisor: _t.Any, /) -> _t.Any: ...
|
|
399
|
+
|
|
400
|
+
def __truediv__(self, divisor: _t.Any, /) -> _t.Any:
|
|
401
|
+
return _to_fraction_if_std_fraction(
|
|
402
|
+
self._value / _to_std_fraction_if_rational(divisor)
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
def __trunc__(self, /) -> int:
|
|
406
|
+
return self._value.__trunc__()
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
@_t.overload
|
|
410
|
+
def _to_fraction_if_std_fraction(value: _Fraction, /) -> Fraction: ...
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
@_t.overload
|
|
414
|
+
def _to_fraction_if_std_fraction(value: _t.Any, /) -> _t.Any: ...
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def _to_fraction_if_std_fraction(value: _t.Any, /) -> _t.Any:
|
|
418
|
+
return (
|
|
419
|
+
Fraction(value.numerator, value.denominator)
|
|
420
|
+
if isinstance(value, _Fraction)
|
|
421
|
+
else value
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
@_t.overload
|
|
426
|
+
def _to_std_fraction_if_rational(value: _numbers.Rational, /) -> _Fraction: ...
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
@_t.overload
|
|
430
|
+
def _to_std_fraction_if_rational(value: _t.Any, /) -> _t.Any: ...
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def _to_std_fraction_if_rational(value: _t.Any, /) -> _t.Any:
|
|
434
|
+
return (
|
|
435
|
+
_Fraction(int(value.numerator), int(value.denominator))
|
|
436
|
+
if isinstance(value, _numbers.Rational)
|
|
437
|
+
else value
|
|
438
|
+
)
|
|
@@ -1,26 +1,49 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cfractions
|
|
3
|
-
Version: 2.
|
|
4
|
-
Summary: Python C API alternative to `fractions` module.
|
|
3
|
+
Version: 2.3.0
|
|
5
4
|
Home-page: https://github.com/lycantropos/cfractions/
|
|
6
5
|
Download-URL: https://github.com/lycantropos/cfractions/archive/master.zip
|
|
7
|
-
Author: Azat Ibrakov
|
|
8
|
-
Author-email: azatibrakov@gmail.com
|
|
6
|
+
Author-email: Azat Ibrakov <azatibrakov@gmail.com>
|
|
9
7
|
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2021 Azat Ibrakov
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
10
29
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
12
30
|
Classifier: Programming Language :: Python :: 3.8
|
|
13
31
|
Classifier: Programming Language :: Python :: 3.9
|
|
14
32
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
33
|
Classifier: Programming Language :: Python :: 3.11
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
35
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
17
36
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
18
|
-
Requires-Python: >=3.
|
|
37
|
+
Requires-Python: >=3.8
|
|
19
38
|
Description-Content-Type: text/markdown
|
|
20
39
|
License-File: LICENSE
|
|
40
|
+
Requires-Dist: typing-extensions>=4.11.0
|
|
41
|
+
Provides-Extra: tests
|
|
42
|
+
Requires-Dist: hypothesis<7.0,>=6.100.1; extra == "tests"
|
|
43
|
+
Requires-Dist: pytest<9.0,>=8.1.2; extra == "tests"
|
|
21
44
|
|
|
22
45
|
cfractions
|
|
23
|
-
|
|
46
|
+
========
|
|
24
47
|
|
|
25
48
|
[](https://github.com/lycantropos/cfractions/actions/workflows/ci.yml "Github Actions")
|
|
26
49
|
[](https://codecov.io/gh/lycantropos/cfractions "Codecov")
|
|
@@ -41,8 +64,8 @@ Main features are:
|
|
|
41
64
|
|
|
42
65
|
---
|
|
43
66
|
|
|
44
|
-
In what follows `python` is an alias for `python3.
|
|
45
|
-
or any later version (`python3.
|
|
67
|
+
In what follows `python` is an alias for `python3.8` or `pypy3.8`
|
|
68
|
+
or any later version (`python3.9`, `pypy3.9` and so on).
|
|
46
69
|
|
|
47
70
|
Installation
|
|
48
71
|
------------
|
|
@@ -69,7 +92,7 @@ cd cfractions
|
|
|
69
92
|
|
|
70
93
|
Install
|
|
71
94
|
```bash
|
|
72
|
-
python
|
|
95
|
+
python -m pip install -e .
|
|
73
96
|
```
|
|
74
97
|
|
|
75
98
|
Usage
|
|
@@ -131,7 +154,7 @@ Bump version
|
|
|
131
154
|
bump2version --verbose $CATEGORY
|
|
132
155
|
```
|
|
133
156
|
|
|
134
|
-
This will set version to `major.minor.patch-alpha`.
|
|
157
|
+
This will set version to `major.minor.patch-alpha`.
|
|
135
158
|
|
|
136
159
|
#### Release
|
|
137
160
|
|
|
@@ -149,9 +172,9 @@ This will set version to `major.minor.patch`.
|
|
|
149
172
|
|
|
150
173
|
### Running tests
|
|
151
174
|
|
|
152
|
-
Install dependencies
|
|
175
|
+
Install with dependencies
|
|
153
176
|
```bash
|
|
154
|
-
python -m pip install -
|
|
177
|
+
python -m pip install -e .[tests]
|
|
155
178
|
```
|
|
156
179
|
|
|
157
180
|
Plain
|