Skip to content

Commit 00ffc45

Browse files
authored
bpo-45440: Remove pymath.c fallbacks (GH-28977)
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.
1 parent 51f8196 commit 00ffc45

File tree

8 files changed

+9
-90
lines changed

8 files changed

+9
-90
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ Build Changes
461461
(Contributed by Mike Gilbert in :issue:`45433`.)
462462

463463
* Building Python now requires a C99 ``<math.h>`` header file providing
464-
``isinf()``, ``isnan()`` and ``isfinite()`` functions.
464+
the following functions: ``copysign()``, ``hypot()``, ``isfinite()``,
465+
``isinf()``, ``isnan()``, ``round()``.
465466
(Contributed by Victor Stinner in :issue:`45440`.)
466467

467468
C API Changes

Include/internal/pycore_pymath.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,6 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
12-
// Python provides implementations for copysign(), round() and hypot() in
13-
// Python/pymath.c just in case your math library doesn't provide the
14-
// functions.
15-
//
16-
// Note: PC/pyconfig.h defines copysign as _copysign
17-
#ifndef HAVE_COPYSIGN
18-
extern double copysign(double, double);
19-
#endif
20-
21-
#ifndef HAVE_ROUND
22-
extern double round(double);
23-
#endif
24-
25-
#ifndef HAVE_HYPOT
26-
extern double hypot(double, double);
27-
#endif
28-
2911
// Extra declarations
3012
#if !defined(_MSC_VER) && !defined(__STDC__)
3113
extern double fmod (double, double);
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Building Python now requires a C99 ``<math.h>`` header file providing
2-
``isinf()``, ``isnan()`` and ``isfinite()`` functions. Patch by Victor Stinner.
2+
the following functions: ``copysign()``, ``hypot()``, ``isfinite()``,
3+
``isinf()``, ``isnan()``, ``round()``.
4+
Patch by Victor Stinner.

PC/pyconfig.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ WIN32 is still required for the locale module.
5858

5959
#include <io.h>
6060

61-
#define HAVE_HYPOT
6261
#define HAVE_STRFTIME
6362
#define DONT_HAVE_SIG_ALARM
6463
#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 */
348347

349348
/* Fairly standard from here! */
350349

351-
/* Define to 1 if you have the `copysign' function. */
352-
#define HAVE_COPYSIGN 1
353-
354-
/* Define to 1 if you have the `round' function. */
355-
#if _MSC_VER >= 1800
356-
# define HAVE_ROUND 1
357-
#endif
358-
359350
/* Define if on AIX 3.
360351
System headers sometimes define this.
361352
We just want to avoid a redefinition error message. */

Python/pymath.c

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,3 @@ void _Py_set_387controlword(unsigned short cw) {
1717
__asm__ __volatile__ ("fldcw %0" : : "m" (cw));
1818
}
1919
#endif // HAVE_GCC_ASM_FOR_X87
20-
21-
22-
#ifndef HAVE_HYPOT
23-
double hypot(double x, double y)
24-
{
25-
double yx;
26-
27-
x = fabs(x);
28-
y = fabs(y);
29-
if (x < y) {
30-
double temp = x;
31-
x = y;
32-
y = temp;
33-
}
34-
if (x == 0.)
35-
return 0.;
36-
else {
37-
yx = y/x;
38-
return x*sqrt(1.+yx*yx);
39-
}
40-
}
41-
#endif /* HAVE_HYPOT */
42-
43-
#ifndef HAVE_COPYSIGN
44-
double
45-
copysign(double x, double y)
46-
{
47-
/* use atan2 to distinguish -0. from 0. */
48-
if (y > 0. || (y == 0. && atan2(y, -1.) > 0.)) {
49-
return fabs(x);
50-
} else {
51-
return -fabs(x);
52-
}
53-
}
54-
#endif /* HAVE_COPYSIGN */
55-
56-
#ifndef HAVE_ROUND
57-
double
58-
round(double x)
59-
{
60-
double absx, y;
61-
absx = fabs(x);
62-
y = floor(absx);
63-
if (absx - y >= 0.5)
64-
y += 1.0;
65-
return copysign(y, x);
66-
}
67-
#endif /* HAVE_ROUND */

configure

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15066,7 +15066,7 @@ fi
1506615066
LIBS_SAVE=$LIBS
1506715067
LIBS="$LIBS $LIBM"
1506815068

15069-
for ac_func in acosh asinh atanh copysign erf erfc expm1 finite gamma
15069+
for ac_func in acosh asinh atanh erf erfc expm1 finite gamma
1507015070
do :
1507115071
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1507215072
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -15078,7 +15078,7 @@ _ACEOF
1507815078
fi
1507915079
done
1508015080

15081-
for ac_func in hypot lgamma log1p log2 round tgamma
15081+
for ac_func in lgamma log1p log2 tgamma
1508215082
do :
1508315083
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1508415084
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4675,8 +4675,8 @@ fi
46754675
LIBS_SAVE=$LIBS
46764676
LIBS="$LIBS $LIBM"
46774677

4678-
AC_CHECK_FUNCS([acosh asinh atanh copysign erf erfc expm1 finite gamma])
4679-
AC_CHECK_FUNCS([hypot lgamma log1p log2 round tgamma])
4678+
AC_CHECK_FUNCS([acosh asinh atanh erf erfc expm1 finite gamma])
4679+
AC_CHECK_FUNCS([lgamma log1p log2 tgamma])
46804680

46814681
# For multiprocessing module, check that sem_open
46824682
# actually works. For FreeBSD versions <= 7.2,

pyconfig.h.in

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@
160160
/* Define to 1 if you have the <conio.h> header file. */
161161
#undef HAVE_CONIO_H
162162

163-
/* Define to 1 if you have the `copysign' function. */
164-
#undef HAVE_COPYSIGN
165-
166163
/* Define to 1 if you have the `copy_file_range' function. */
167164
#undef HAVE_COPY_FILE_RANGE
168165

@@ -538,9 +535,6 @@
538535
/* Define this if you have le64toh() */
539536
#undef HAVE_HTOLE64
540537

541-
/* Define to 1 if you have the `hypot' function. */
542-
#undef HAVE_HYPOT
543-
544538
/* Define to 1 if you have the <ieeefp.h> header file. */
545539
#undef HAVE_IEEEFP_H
546540

@@ -872,9 +866,6 @@
872866
/* Define if you have readline 4.0 */
873867
#undef HAVE_RL_RESIZE_TERMINAL
874868

875-
/* Define to 1 if you have the `round' function. */
876-
#undef HAVE_ROUND
877-
878869
/* Define to 1 if you have the `rtpSpawn' function. */
879870
#undef HAVE_RTPSPAWN
880871

0 commit comments

Comments
 (0)