To implement the PEP 485 (math.isclose), I proposed to split the math module into two parts: _math (C) and math (py). The current C module is renamed to _math and a new "math" module implementd in Python is added. The math module contains "from _math import *".
Attached patch implements this idea.
math.py contains the Python implementation of the following functions:
- degrees
- fsum
- factorial
- radians
I propose to add these functions to "document" the implementation of these functions, I don't want to use the Python implementation by default.
Maybe _math.degrees() and _math.radians() can be removed, the Python implementation is enough.
I'm not sure that the C implementation of factorial() is much faster, since most part of the C code calls Python functions (boxing/unboxing). But it's probably better to keep the C implementation :-)
I don't understand how _factorial_partial_product() decide to divide the computation using the number of bits. Does it make sense to compute the number of bits in Python, since the Python int type has no limit? (only memory)
The C and Python implementations are tested by test_math.
math.py cannot be used alone: it requires floor(), isfinite(), isinf() and isnan() functions of the _math module. The "try: import _math except ImportError: pass" is only useful for unit tests.
TODO: remove SIZEOF_LONG from math.py.
We may rename Module/mathmodule.c to Module/_mathmodule.c, but it's not convinient to generate a patch if a file is renamed. |