Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61190e0

Browse files
authored
bpo-45412: Move copysign() define to pycore_pymath.h (GH-28889)
Move definitions of copysign(), round(), hypot(), fmod(), etc. from pymath.h to pycore_pymath.h. These functions are not exported by libpython and so must not be part of the C API.
1 parent 1f316ea commit 61190e0

2 files changed

Lines changed: 49 additions & 52 deletions

File tree

Include/internal/pycore_pymath.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@ 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+
29+
// Extra declarations
30+
#if !defined(_MSC_VER) && !defined(__STDC__)
31+
extern double fmod (double, double);
32+
extern double frexp (double, int *);
33+
extern double ldexp (double, int);
34+
extern double modf (double, double *);
35+
extern double pow(double, double);
36+
#endif // !defined(_MSC_VER) && !defined(__STDC__)
37+
38+
1139
/* _Py_ADJUST_ERANGE1(x)
1240
* _Py_ADJUST_ERANGE2(x, y)
1341
* Set errno to 0 before calling a libm function, and invoke one of these

Include/pymath.h

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,10 @@
1+
// Symbols and macros to supply platform-independent interfaces to mathematical
2+
// functions and constants.
3+
14
#ifndef Py_PYMATH_H
25
#define Py_PYMATH_H
36

4-
#include "pyconfig.h" /* include for defines */
5-
6-
/**************************************************************************
7-
Symbols and macros to supply platform-independent interfaces to mathematical
8-
functions and constants
9-
**************************************************************************/
10-
11-
/* Python provides implementations for copysign, round and hypot in
12-
* Python/pymath.c just in case your math library doesn't provide the
13-
* functions.
14-
*
15-
*Note: PC/pyconfig.h defines copysign as _copysign
16-
*/
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-
29-
/* extra declarations */
30-
#ifndef _MSC_VER
31-
#ifndef __STDC__
32-
extern double fmod (double, double);
33-
extern double frexp (double, int *);
34-
extern double ldexp (double, int);
35-
extern double modf (double, double *);
36-
extern double pow(double, double);
37-
#endif /* __STDC__ */
38-
#endif /* _MSC_VER */
7+
#include "pyconfig.h" // HAVE_DECL_ISNAN
398

409
/* High precision definition of pi and e (Euler)
4110
* The values are taken from libc6's math.h.
@@ -123,13 +92,13 @@ PyAPI_FUNC(double) _Py_force_double(double);
12392
* Note: PC/pyconfig.h defines Py_IS_FINITE as _finite
12493
*/
12594
#ifndef Py_IS_FINITE
126-
#if defined HAVE_DECL_ISFINITE && HAVE_DECL_ISFINITE == 1
127-
#define Py_IS_FINITE(X) isfinite(X)
128-
#elif defined HAVE_FINITE
129-
#define Py_IS_FINITE(X) finite(X)
130-
#else
131-
#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
132-
#endif
95+
# if defined HAVE_DECL_ISFINITE && HAVE_DECL_ISFINITE == 1
96+
# define Py_IS_FINITE(X) isfinite(X)
97+
# elif defined HAVE_FINITE
98+
# define Py_IS_FINITE(X) finite(X)
99+
# else
100+
# define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
101+
# endif
133102
#endif
134103

135104
/* HUGE_VAL is supposed to expand to a positive double infinity. Python
@@ -140,7 +109,7 @@ PyAPI_FUNC(double) _Py_force_double(double);
140109
* config to #define Py_HUGE_VAL to something that works on your platform.
141110
*/
142111
#ifndef Py_HUGE_VAL
143-
#define Py_HUGE_VAL HUGE_VAL
112+
# define Py_HUGE_VAL HUGE_VAL
144113
#endif
145114

146115
/* Py_NAN
@@ -149,10 +118,10 @@ PyAPI_FUNC(double) _Py_force_double(double);
149118
* doesn't support NaNs.
150119
*/
151120
#if !defined(Py_NAN) && !defined(Py_NO_NAN)
152-
#if !defined(__INTEL_COMPILER)
153-
#define Py_NAN (Py_HUGE_VAL * 0.)
154-
#else /* __INTEL_COMPILER */
155-
#if defined(ICC_NAN_STRICT)
121+
# if !defined(__INTEL_COMPILER)
122+
# define Py_NAN (Py_HUGE_VAL * 0.)
123+
# else /* __INTEL_COMPILER */
124+
# if defined(ICC_NAN_STRICT)
156125
#pragma float_control(push)
157126
#pragma float_control(precise, on)
158127
#pragma float_control(except, on)
@@ -161,12 +130,12 @@ PyAPI_FUNC(double) _Py_force_double(double);
161130
return sqrt(-1.0);
162131
}
163132
#pragma float_control (pop)
164-
#define Py_NAN __icc_nan()
165-
#else /* ICC_NAN_RELAXED as default for Intel Compiler */
133+
# define Py_NAN __icc_nan()
134+
# else /* ICC_NAN_RELAXED as default for Intel Compiler */
166135
static const union { unsigned char buf[8]; double __icc_nan; } __nan_store = {0,0,0,0,0,0,0xf8,0x7f};
167-
#define Py_NAN (__nan_store.__icc_nan)
168-
#endif /* ICC_NAN_STRICT */
169-
#endif /* __INTEL_COMPILER */
136+
# define Py_NAN (__nan_store.__icc_nan)
137+
# endif /* ICC_NAN_STRICT */
138+
# endif /* __INTEL_COMPILER */
170139
#endif
171140

172141
#endif /* Py_PYMATH_H */

0 commit comments

Comments
 (0)