[Python-ideas] Make Python front end to the C math module
Steven D'Aprano
steve at pearwood.info
Sun Jun 19 21:11:54 EDT 2016
On Sun, Jun 19, 2016 at 06:04:47PM +0100, Paul Moore wrote:
> On 19 June 2016 at 16:02, Steven D'Aprano <steve at pearwood.info> wrote:
> >
> > For the avoidance of doubt, there is NO requirement for pure-Python
> > implementations of the existing math functions, or even future ones.
> > Future functions can go straight into the C implementation is desired.
> > This is to allow future functions the opportunity to be written in
> > Python.
>
> Is there any reason to do this in advance of an actual requirement for
> it? It seems to me that doing this when someone proposes a
> Python-coded math function would be fine.
Now that you mention it, I do have an actual requirement:
http://bugs.python.org/issue27353
> Or do you think that the
> fact that math is coded in C is stopping people even suggesting
> additions, because they believe they'd need to be able to write them
> in C?
Its hard to say whether its stopping people from *proposing* new
functionality, since talk is cheap. But its certainly a barrier to
having them propose actual patches, since they must be written in C.
To anticipate a likely objection, that math was originally conceived as
a platform-specific thin wrapper around the C math library, I think
that's well and truly past:
- math is not limited to the C89 math library;
- but nor does it contain all of the C99 math library (there's
quite a bit missing);
- and it includes functions not found in either C89 or C99.
Python tries to smooth out platform specific differences regarding
float, e.g. float('nan') works on all platforms, not just POSIX (Windows
used to require '1.#IND').
I think it is fair to say that math will be closely aligned to your
platform's C math library, but it is not restricted to that. I think the
current documentation is clear:
CPython implementation detail: The math module consists MOSTLY of thin
wrappers around the platform C math library functions. [emphasis added]
https://docs.python.org/3/library/math.html#constants
--
Steve
More information about the Python-ideas
mailing list