Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa26245

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 remainingworkaround 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 parent51ed2c5 commitfa26245

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-
#ifdefHAVE_ACOSH
2-
# definem_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(doublex);
7-
# definem_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-
#ifdefHAVE_ASINH
11-
# definem_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(doublex);
16-
# definem_asinh _Py_asinh
17-
#endif
7+
staticdouble
8+
_Py_log1p(doublex)
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-
#ifdefHAVE_ATANH
20-
# definem_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(doublex);
25-
#definem_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+
returnx;
18+
}
19+
else {
20+
returnlog1p(x);
21+
}
22+
}
2723

28-
#ifdefHAVE_EXPM1
29-
# definem_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(doublex);
34-
#definem_expm1 _Py_expm1
35-
#endif
36-
37-
double_Py_log1p(doublex);
38-
39-
/* Use the substitute from _math.c on all platforms:
40-
it includes workarounds for buggy handling of zeros. */
4124
#definem_log1p _Py_log1p

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp