]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45440: Remove pymath.c fallbacks (GH-28977)
authorVictor Stinner <vstinner@python.org>
Fri, 15 Oct 2021 17:45:34 +0000 (19:45 +0200)
committerGitHub <noreply@github.com>
Fri, 15 Oct 2021 17:45:34 +0000 (19:45 +0200)
Remove fallbacks for missing round(), copysign() and hypot() in
Python/pymath.c. Python now requires these functions to build.

These fallbacks were needed on Visual Studio 2012 and older. They are
no longer needed since Visual Stuido 2013. Python is now built with
Visual Studio 2017 or newer since Python 3.6.

Doc/whatsnew/3.11.rst
Include/internal/pycore_pymath.h
Misc/NEWS.d/next/Build/2021-10-12-02-13-08.bpo-45440.-zYgDb.rst
PC/pyconfig.h
Python/pymath.c
configure
configure.ac
pyconfig.h.in

index 4704be5715426a2dc0b8e6cbea795cceafed2aa6..9d7d3f19faae83771b27e088605e04ad67f8766d 100644 (file)
@@ -461,7 +461,8 @@ Build Changes
   (Contributed by Mike Gilbert in :issue:`45433`.)
 
 * Building Python now requires a C99 ``<math.h>`` header file providing
-  ``isinf()``, ``isnan()`` and ``isfinite()`` functions.
+  the following functions: ``copysign()``, ``hypot()``, ``isfinite()``,
+  ``isinf()``, ``isnan()``, ``round()``.
   (Contributed by Victor Stinner in :issue:`45440`.)
 
 C API Changes
index 32743fc83f5c0376069956fd31dfed3716207c56..395b71452e40ad1a911aff28aa730fe7a1db59b9 100644 (file)
@@ -8,24 +8,6 @@ extern "C" {
 #  error "this header requires Py_BUILD_CORE define"
 #endif
 
-
-// Python provides implementations for copysign(), round() and hypot() in
-// Python/pymath.c just in case your math library doesn't provide the
-// functions.
-//
-// Note: PC/pyconfig.h defines copysign as _copysign
-#ifndef HAVE_COPYSIGN
-extern double copysign(double, double);
-#endif
-
-#ifndef HAVE_ROUND
-extern double round(double);
-#endif
-
-#ifndef HAVE_HYPOT
-extern double hypot(double, double);
-#endif
-
 // Extra declarations
 #if !defined(_MSC_VER) && !defined(__STDC__)
 extern double fmod (double, double);
index 1c7c413155f45d2cb1214ec7e6786754aed3d3c7..93f7f3139065fbf857638bee8a1abbf9d0c09992 100644 (file)
@@ -1,2 +1,4 @@
 Building Python now requires a C99 ``<math.h>`` header file providing
-``isinf()``, ``isnan()`` and ``isfinite()`` functions. Patch by Victor Stinner.
+the following functions: ``copysign()``, ``hypot()``, ``isfinite()``,
+``isinf()``, ``isnan()``, ``round()``.
+Patch by Victor Stinner.
index 75397772280dcd2990a9bbc195260555e4d74f20..bb55ff4fe14c4714d464ea120c54c2a0fbf13bc1 100644 (file)
@@ -58,7 +58,6 @@ WIN32 is still required for the locale module.
 
 #include <io.h>
 
-#define HAVE_HYPOT
 #define HAVE_STRFTIME
 #define DONT_HAVE_SIG_ALARM
 #define DONT_HAVE_SIG_PAUSE
@@ -348,14 +347,6 @@ Py_NO_ENABLE_SHARED to find out.  Also support MS_NO_COREDLL for b/w compat */
 
 /* Fairly standard from here! */
 
-/* Define to 1 if you have the `copysign' function. */
-#define HAVE_COPYSIGN 1
-
-/* Define to 1 if you have the `round' function. */
-#if _MSC_VER >= 1800
-#  define HAVE_ROUND 1
-#endif
-
 /* Define if on AIX 3.
    System headers sometimes define this.
    We just want to avoid a redefinition error message.  */
index b2681f2acc1f02bf58915d6009b7a9067fb7a64d..e7d0161ff94c2e147f22908bc9559cb556425e88 100644 (file)
@@ -17,51 +17,3 @@ void _Py_set_387controlword(unsigned short cw) {
     __asm__ __volatile__ ("fldcw %0" : : "m" (cw));
 }
 #endif  // HAVE_GCC_ASM_FOR_X87
-
-
-#ifndef HAVE_HYPOT
-double hypot(double x, double y)
-{
-    double yx;
-
-    x = fabs(x);
-    y = fabs(y);
-    if (x < y) {
-        double temp = x;
-        x = y;
-        y = temp;
-    }
-    if (x == 0.)
-        return 0.;
-    else {
-        yx = y/x;
-        return x*sqrt(1.+yx*yx);
-    }
-}
-#endif /* HAVE_HYPOT */
-
-#ifndef HAVE_COPYSIGN
-double
-copysign(double x, double y)
-{
-    /* use atan2 to distinguish -0. from 0. */
-    if (y > 0. || (y == 0. && atan2(y, -1.) > 0.)) {
-        return fabs(x);
-    } else {
-        return -fabs(x);
-    }
-}
-#endif /* HAVE_COPYSIGN */
-
-#ifndef HAVE_ROUND
-double
-round(double x)
-{
-    double absx, y;
-    absx = fabs(x);
-    y = floor(absx);
-    if (absx - y >= 0.5)
-        y += 1.0;
-    return copysign(y, x);
-}
-#endif /* HAVE_ROUND */
index c56ff1dc5cd6aea963110ab773ca41d82d9d1434..81ee4282d9412bd526c9bf0965890a7c5afcbaae 100755 (executable)
--- a/configure
+++ b/configure
@@ -15066,7 +15066,7 @@ fi
 LIBS_SAVE=$LIBS
 LIBS="$LIBS $LIBM"
 
-for ac_func in acosh asinh atanh copysign erf erfc expm1 finite gamma
+for ac_func in acosh asinh atanh erf erfc expm1 finite gamma
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -15078,7 +15078,7 @@ _ACEOF
 fi
 done
 
-for ac_func in hypot lgamma log1p log2 round tgamma
+for ac_func in lgamma log1p log2 tgamma
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
index 1d0c753efac1a95809456dc752704d28b5ee116f..ab3fc2839d4f8b46f7b674900a033adf4b042e8b 100644 (file)
@@ -4675,8 +4675,8 @@ fi
 LIBS_SAVE=$LIBS
 LIBS="$LIBS $LIBM"
 
-AC_CHECK_FUNCS([acosh asinh atanh copysign erf erfc expm1 finite gamma])
-AC_CHECK_FUNCS([hypot lgamma log1p log2 round tgamma])
+AC_CHECK_FUNCS([acosh asinh atanh erf erfc expm1 finite gamma])
+AC_CHECK_FUNCS([lgamma log1p log2 tgamma])
 
 # For multiprocessing module, check that sem_open
 # actually works.  For FreeBSD versions <= 7.2,
index 43a04e371a594136d17391c00b350af9bf63d171..a426e8effddb9fe061594575c6ba88eddcee0d53 100644 (file)
 /* Define to 1 if you have the <conio.h> header file. */
 #undef HAVE_CONIO_H
 
-/* Define to 1 if you have the `copysign' function. */
-#undef HAVE_COPYSIGN
-
 /* Define to 1 if you have the `copy_file_range' function. */
 #undef HAVE_COPY_FILE_RANGE
 
 /* Define this if you have le64toh() */
 #undef HAVE_HTOLE64
 
-/* Define to 1 if you have the `hypot' function. */
-#undef HAVE_HYPOT
-
 /* Define to 1 if you have the <ieeefp.h> header file. */
 #undef HAVE_IEEEFP_H
 
 /* Define if you have readline 4.0 */
 #undef HAVE_RL_RESIZE_TERMINAL
 
-/* Define to 1 if you have the `round' function. */
-#undef HAVE_ROUND
-
 /* Define to 1 if you have the `rtpSpawn' function. */
 #undef HAVE_RTPSPAWN