Skip to content

bpo-45548: Remove _math.c workarounds for pre-C99 libm #29179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,6 @@ pybuilddir.txt: $(BUILDPYTHON)
exit 1 ; \
fi

# This is shared by the math and cmath modules
Modules/_math.o: Modules/_math.c Modules/_math.h
$(CC) -c $(CCSHARED) $(PY_CORE_CFLAGS) -o $@ $<

# blake2s is auto-generated from blake2b
$(srcdir)/Modules/_blake2/blake2s_impl.c: $(srcdir)/Modules/_blake2/blake2b_impl.c $(srcdir)/Modules/_blake2/blake2b2s.py
$(PYTHON_FOR_REGEN) $(srcdir)/Modules/_blake2/blake2b2s.py
Expand All @@ -625,7 +621,7 @@ $(srcdir)/Modules/_blake2/blake2s_impl.c: $(srcdir)/Modules/_blake2/blake2b_impl
# -s, --silent or --quiet is always the first char.
# Under BSD make, MAKEFLAGS might be " -s -v x=y".
# Ignore macros passed by GNU make, passed after --
sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o
sharedmods: $(BUILDPYTHON) pybuilddir.txt
@case "`echo X $$MAKEFLAGS | sed 's/^X //;s/ -- .*//'`" in \
*\ -s*|s*) quiet="-q";; \
*) quiet="";; \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The :mod:`math` and :mod:`cmath` implementation now require a C99 compatible
``libm`` and no longer ship with workarounds for missing acosh, asinh, atanh,
expm1, and log1p functions.
4 changes: 2 additions & 2 deletions Modules/Setup
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ time timemodule.c
#array arraymodule.c
#audioop audioop.c
#binascii binascii.c
#cmath cmathmodule.c _math.c # -lm
#math mathmodule.c _math.c # -lm
#cmath cmathmodule.c # -lm
#math mathmodule.c # -lm
#pyexpat -I$(srcdir)/Modules/expat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c
#unicodedata unicodedata.c

Expand Down
270 changes: 0 additions & 270 deletions Modules/_math.c

This file was deleted.

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

#ifdef HAVE_ASINH
# define m_asinh asinh
#else
/* if the system doesn't have asinh, use the substitute
function defined in Modules/_math.c. */
double _Py_asinh(double x);
# define m_asinh _Py_asinh
#endif
static double
_Py_log1p(double x)
{
/* Some platforms supply a log1p function but don't respect the sign of
zero: log1p(-0.0) gives 0.0 instead of the correct result of -0.0.

#ifdef HAVE_ATANH
# define m_atanh atanh
#else
/* if the system doesn't have atanh, use the substitute
function defined in Modules/_math.c. */
double _Py_atanh(double x);
#define m_atanh _Py_atanh
#endif
To save fiddling with configure tests and platform checks, we handle the
special case of zero input directly on all platforms.
*/
if (x == 0.0) {
return x;
}
else {
return log1p(x);
}
}

#ifdef HAVE_EXPM1
# define m_expm1 expm1
#else
/* if the system doesn't have expm1, use the substitute
function defined in Modules/_math.c. */
double _Py_expm1(double x);
#define m_expm1 _Py_expm1
#endif

double _Py_log1p(double x);

/* Use the substitute from _math.c on all platforms:
it includes workarounds for buggy handling of zeros. */
#define m_log1p _Py_log1p
Loading