summaryrefslogtreecommitdiffstats
path: root/Modules/_math.h
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2021-10-25 08:25:27 (GMT)
committerGitHub <noreply@github.com>2021-10-25 08:25:27 (GMT)
commitfa26245a1c1aa938cce391348d6bd879da357522 (patch)
treeb193ebf766f3105a880ce8d8f7160b090b0c77b2 /Modules/_math.h
parent51ed2c56a1852cd6b09c85ba81312dc9782772ce (diff)
downloadcpython-fa26245a1c1aa938cce391348d6bd879da357522.zip
cpython-fa26245a1c1aa938cce391348d6bd879da357522.tar.gz
cpython-fa26245a1c1aa938cce391348d6bd879da357522.tar.bz2
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>
Diffstat (limited to 'Modules/_math.h')
-rw-r--r--Modules/_math.h57
1 files changed, 20 insertions, 37 deletions
diff --git a/Modules/_math.h b/Modules/_math.h
index 398b7e8..4a6bc22 100644
--- a/Modules/_math.h
+++ b/Modules/_math.h
@@ -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