|
4 | 4 | #ifndef Py_PYMATH_H |
5 | 5 | #define Py_PYMATH_H |
6 | 6 |
|
7 | | -#include "pyconfig.h" // HAVE_DECL_ISNAN |
8 | | - |
9 | 7 | /* High precision definition of pi and e (Euler) |
10 | 8 | * The values are taken from libc6's math.h. |
11 | 9 | */ |
|
29 | 27 | #define Py_MATH_TAU 6.2831853071795864769252867665590057683943L |
30 | 28 | #endif |
31 | 29 |
|
| 30 | +// Py_IS_NAN(X) |
| 31 | +// Return 1 if float or double arg is a NaN, else 0. |
| 32 | +#define Py_IS_NAN(X) isnan(X) |
32 | 33 |
|
33 | | -/* On x86, Py_FORCE_DOUBLE forces a floating-point number out of an x87 FPU |
34 | | - register and into a 64-bit memory location, rounding from extended |
35 | | - precision to double precision in the process. On other platforms it does |
36 | | - nothing. */ |
37 | | - |
38 | | -/* we take double rounding as evidence of x87 usage */ |
39 | | -#ifndef Py_LIMITED_API |
40 | | -#ifndef Py_FORCE_DOUBLE |
41 | | -# ifdef X87_DOUBLE_ROUNDING |
42 | | -PyAPI_FUNC(double) _Py_force_double(double); |
43 | | -# define Py_FORCE_DOUBLE(X) (_Py_force_double(X)) |
44 | | -# else |
45 | | -# define Py_FORCE_DOUBLE(X) (X) |
46 | | -# endif |
47 | | -#endif |
48 | | -#endif |
49 | | - |
50 | | -/* Py_IS_NAN(X) |
51 | | - * Return 1 if float or double arg is a NaN, else 0. |
52 | | - * Caution: |
53 | | - * X is evaluated more than once. |
54 | | - * This may not work on all platforms. Each platform has *some* |
55 | | - * way to spell this, though -- override in pyconfig.h if you have |
56 | | - * a platform where it doesn't work. |
57 | | - * Note: PC/pyconfig.h defines Py_IS_NAN as _isnan |
58 | | - */ |
59 | | -#ifndef Py_IS_NAN |
60 | | -# if defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 1 |
61 | | -# define Py_IS_NAN(X) isnan(X) |
62 | | -# else |
63 | | -# define Py_IS_NAN(X) ((X) != (X)) |
64 | | -# endif |
65 | | -#endif |
66 | | - |
67 | | -/* Py_IS_INFINITY(X) |
68 | | - * Return 1 if float or double arg is an infinity, else 0. |
69 | | - * Caution: |
70 | | - * X is evaluated more than once. |
71 | | - * This implementation may set the underflow flag if |X| is very small; |
72 | | - * it really can't be implemented correctly (& easily) before C99. |
73 | | - * Override in pyconfig.h if you have a better spelling on your platform. |
74 | | - * Py_FORCE_DOUBLE is used to avoid getting false negatives from a |
75 | | - * non-infinite value v sitting in an 80-bit x87 register such that |
76 | | - * v becomes infinite when spilled from the register to 64-bit memory. |
77 | | - * Note: PC/pyconfig.h defines Py_IS_INFINITY as _isinf |
78 | | - */ |
79 | | -#ifndef Py_IS_INFINITY |
80 | | -# if defined HAVE_DECL_ISINF && HAVE_DECL_ISINF == 1 |
81 | | -# define Py_IS_INFINITY(X) isinf(X) |
82 | | -# else |
83 | | -# define Py_IS_INFINITY(X) ((X) && \ |
84 | | - (Py_FORCE_DOUBLE(X)*0.5 == Py_FORCE_DOUBLE(X))) |
85 | | -# endif |
86 | | -#endif |
| 34 | +// Py_IS_INFINITY(X) |
| 35 | +// Return 1 if float or double arg is an infinity, else 0. |
| 36 | +#define Py_IS_INFINITY(X) isinf(X) |
87 | 37 |
|
88 | | -/* Py_IS_FINITE(X) |
89 | | - * Return 1 if float or double arg is neither infinite nor NAN, else 0. |
90 | | - * Some compilers (e.g. VisualStudio) have intrinsics for this, so a special |
91 | | - * macro for this particular test is useful |
92 | | - * Note: PC/pyconfig.h defines Py_IS_FINITE as _finite |
93 | | - */ |
94 | | -#ifndef Py_IS_FINITE |
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 |
102 | | -#endif |
| 38 | +// Py_IS_FINITE(X) |
| 39 | +// Return 1 if float or double arg is neither infinite nor NAN, else 0. |
| 40 | +#define Py_IS_FINITE(X) isfinite(X) |
103 | 41 |
|
104 | 42 | /* HUGE_VAL is supposed to expand to a positive double infinity. Python |
105 | 43 | * uses Py_HUGE_VAL instead because some platforms are broken in this |
|
0 commit comments