8000 bpo-45548: Remove _math.c workarounds for pre-C99 libm (GH-29179) · python/cpython@fa26245 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa26245

Browse files
tiranmdickinsonbrettcannon
authored
bpo-45548: Remove _math.c workarounds for pre-C99 libm (GH-29179)
The :mod:`math` and :mod:`cmath` implementation now require a C99 compatible ``libm`` and no longer ship with workarounds for missing acosh, asinh, expm1, and log1p functions. The changeset also removes ``_math.c`` and moves the last remaining workaround into ``_math.h``. This simplifies static builds with ``Modules/Setup`` and resolves symbol conflicts. Co-authored-by: Mark Dickinson <mdickinson@enthought.com> Co-authored-by: Brett Cannon <brett@python.org> Signed-off-by: Christian Heimes <christian@python.org>
1 parent 51ed2c5 commit fa26245

File tree

12 files changed

+51
-346
lines changed

12 files changed

+51
-346
lines changed

Makefile.pre.in

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,6 @@ pybuilddir.txt: $(BUILDPYTHON)
611611
exit 1 ; \
612612
fi
613613

614-
# This is shared by the math and cmath modules
615-
Modules/_math.o: Modules/_math.c Modules/_math.h
616-
$(CC) -c $(CCSHARED) $(PY_CORE_CFLAGS) -o $@ $<
617-
618614
# blake2s is auto-generated from blake2b
619615
$(srcdir)/Modules/_blake2/blake2s_impl.c: $(srcdir)/Modules/_blake2/blake2b_impl.c $(srcdir)/Modules/_blake2/blake2b2s.py
620616
$(PYTHON_FOR_REGEN) $(srcdir)/Modules/_blake2/blake2b2s.py
@@ -625,7 +621,7 @@ $(srcdir)/Modules/_blake2/blake2s_impl.c: $(srcdir)/Modules/_blake2/blake2b_impl
625621
# -s, --silent or --quiet is always the first char.
626622
# Under BSD make, MAKEFLAGS might be " -s -v x=y".
627623
# Ignore macros passed by GNU make, passed after --
628-
sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o
624+
sharedmods: $(BUILDPYTHON) pybuilddir.txt
629625
@case "`echo X $$MAKEFLAGS | sed 's/^X //;s/ -- .*//'`" in \
630626
*\ -s*|s*) quiet="-q";; \
631627
*) quiet="";; \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The :mod:`math` and :mod:`cmath` implementation now require a C99 compatible
2+
``libm`` and no longer ship with workarounds for missing acosh, asinh, atanh,
3+
expm1, and log1p functions.

Modules/Setup

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ time timemodule.c
171171
#array arraymodule.c
172172
#audioop audioop.c
173173
#binascii binascii.c
174-
#cmath cmathmodule.c _math.c # -lm
175-
#math mathmodule.c _math.c # -lm
174+
#cmath cmathmodule.c # -lm
175+
#math mathmodule.c # -lm
176176
#pyexpat -I$(srcdir)/Modules/expat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c
177177
#unicodedata unicodedata.c
178178

Modules/_math.c

Lines changed: 0 additions & 270 deletions
This file was deleted.

Modules/_math.h

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,24 @@
1-
#ifdef HAVE_ACOSH
2-
# define m_acosh acosh
3-
#else
4-
/* if the system doesn't have acosh, use the substitute
5-
function defined in Modules/_math.c. */
6-
double _Py_acosh(double x);
7-
# define m_acosh _Py_acosh
8-
#endif
1+
/* log1p(x) = log(1+x). The log1p function is designed to avoid the
2+
significant loss of precision that arises from direct evaluation when x is
3+
small. Use the substitute from _math.h on all platforms: it includes
4+
workarounds for buggy handling of zeros.
5+
*/
96

10-
#ifdef HAVE_ASINH
11-
# define m_asinh asinh
12-
#else
13-
/* if the system doesn't have asinh, use the substitute
14-
function defined in Modules/_math.c. */
15-
double _Py_asinh(double x);
16-
# define m_asinh _Py_asinh
17-
#endif
7+
static double
8+
_Py_log1p(double x)
9+
{
10+
/* Some platforms supply a log1p function but don't respect the sign of
11+
zero: log1p(-0.0) gives 0.0 instead of the correct result of -0.0.
1812
19-
#ifdef HAVE_ATANH
20-
# define m_atanh atanh
21-
#else
22-
/* if the system doesn't have atanh, use the substitute
23-
function defined in Modules/_math.c. */
24-
double _Py_atanh(double x);
25-
#define m_atanh _Py_atanh
26-
#endif
13+
To save fiddling with configure tests and platform checks, we handle the
14+
special case of zero input directly on all platforms.
15+
*/
16+
if (x == 0.0) {
17+
return x;
18+
}
19+
else {
20+
return log1p(x);
21+
}
22+
}
2723

28-
#ifdef HAVE_EXPM1
29-
# define m_expm1 expm1
30-
#else
31-
/* if the system doesn't have expm1, use the substitute
32-
function defined in Modules/_math.c. */
33-
double _Py_expm1(double x);
34-
#define m_expm1 _Py_expm1
35-
#endif
36-
37-
double _Py_log1p(double x);
38-
39-
/* Use the substitute from _math.c on all platforms:
40-
it includes workarounds for buggy handling of zeros. */
4124
#define m_log1p _Py_log1p

0 commit comments

Comments
 (0)
0