Skip to content

Commit be15a36

Browse files
authored
PEP 791: address PEP review comments (part 2) (#4522)
* emphasize: no backward-incompatible changes * expand history of the proposal * Motivation: what people should expect about factorial() output? * add n_div() proposal, rename ceil_div() like gmpy2
1 parent d3103fb commit be15a36

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

peps/pep-0791.rst

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ return values are integers." would be accurate. In a similar way we
3939
can simplify the description of the accepted arguments for functions in both the
4040
new module and in :external+py3.14:mod:`math`.
4141

42+
Now it's a lot harder to satisfy people's expectations about the module
43+
content. For example, should they expect that ``math.factorial(100)`` will
44+
return an exact answer? Many languages, Python packages (like :pypi:`scipy`)
45+
or pocket calculators have functions with same or similar name, that return a
46+
floating-point value, which is only an approximation in this example.
47+
4248
Apparently, the :external+py3.14:mod:`math` module can't serve as a catch-all place
4349
for mathematical functions since we also have the :external+py3.14:mod:`cmath` and
4450
:external+py3.14:mod:`statistics` modules. Let's do the same for integer-related
@@ -56,16 +62,26 @@ And this situation tends to get worse. When the module split `was first
5662
proposed
5763
<https://mail.python.org/archives/list/[email protected]/thread/YYJ5YJBJNCVXQWK5K3WSVNMPUSV56LOR/>`_,
5864
there were only two integer-related functions:
59-
:external+py3.14:func:`~math.factorial` and :external+py3.14:func:`~math.gcd`.
60-
Now there are six and :external+py3.14:func:`~math.factorial` doesn't accept
65+
:external+py3.14:func:`~math.factorial` (accepting also :class:`float`'s, like other
66+
functions in the module) and :external+py3.14:func:`~math.gcd` (moved from the
67+
::external+py3.14:mod:`fractions` module). Then
68+
:external+py3.14:func:`~math.isqrt`, :external+py3.14:func:`~math.comb` and
69+
:external+py3.14:func:`~math.perm` were added, and addition of the new module
70+
was `proposed second time <https://github.com/python/cpython/issues/81313>`_,
71+
so all new functions would go directly to it, without littering the
72+
:external+py3.14:mod:`math` namespace.
73+
Now there are six functions and :external+py3.14:func:`~math.factorial` doesn't accept
6174
:class:`float`'s anymore.
6275

6376
Some possible additions, among those proposed in the initial discussion thread
6477
and issue
6578
`python/cpython#81313 <https://github.com/python/cpython/issues/81313>`_ are:
6679

67-
* ``ceil_div()`` --- for integer ceiling divide, see
68-
`relevant discussion thread <https://discuss.python.org/t/91269>`_.
80+
* ``c_div()`` and ``n_div()`` --- for integer division with rounding towards
81+
positive infinity (ceiling divide) and to the nearest integer, see `relevant
82+
discussion thread <https://discuss.python.org/t/91269>`_. This is reinvented
83+
several times in the stdlib, e.g. in the :mod:`datetime` and the
84+
:mod:`fractions`.
6985
* ``gcdext()`` --- to solve linear `Diophantine equation <https://en.wikipedia.org/wiki/Diophantine_equation>`_ in two variables (the
7086
:external+py3.14:class:`int` implementation actually includes an extended
7187
Euclidean algorithm)
@@ -110,6 +126,7 @@ module, called ``intmath``:
110126
* :external+py3.14:func:`~math.perm`
111127

112128
Their aliases in :external+py3.14:mod:`math` will be :term:`soft deprecated`.
129+
This PEP doesn't introduce backward-incompatible changes.
113130

114131
Module functions will accept integers and objects that implement the
115132
:external+py3.14:meth:`~object.__index__` method, which is used to convert the

0 commit comments

Comments
 (0)