4 #include "pyconfig.h" /* include for defines */
10 /**************************************************************************
11 Symbols and macros to supply platform-independent interfaces to mathematical
12 functions and constants
13 **************************************************************************/
15 /* Python provides implementations for copysign, acosh, asinh, atanh,
16 * log1p and hypot in Python/pymath.c just in case your math library doesn't
17 * provide the functions.
19 *Note: PC/pyconfig.h defines copysign as _copysign
22 extern double copysign(doube
, double);
26 extern double acosh(double);
30 extern double asinh(double);
34 extern double atanh(double);
38 extern double log1p(double);
42 extern double hypot(double, double);
45 /* extra declarations */
48 extern double fmod (double, double);
49 extern double frexp (double, int *);
50 extern double ldexp (double, int);
51 extern double modf (double, double *);
52 extern double pow(double, double);
57 /* OSF1 5.1 doesn't make these available with XOPEN_SOURCE_EXTENDED defined */
58 extern int finite(double);
59 extern double copysign(double, double);
62 /* High precision defintion of pi and e (Euler)
63 * The values are taken from libc6's math.h.
66 #define Py_MATH_PIl 3.1415926535897932384626433832795029L
69 #define Py_MATH_PI 3.14159265358979323846
73 #define Py_MATH_El 2.7182818284590452353602874713526625L
77 #define Py_MATH_E 2.7182818284590452354
81 * Return 1 if float or double arg is a NaN, else 0.
83 * X is evaluated more than once.
84 * This may not work on all platforms. Each platform has *some*
85 * way to spell this, though -- override in pyconfig.h if you have
86 * a platform where it doesn't work.
87 * Note: PC/pyconfig.h defines Py_IS_NAN as _isnan
91 #define Py_IS_NAN(X) isnan(X)
93 #define Py_IS_NAN(X) ((X) != (X))
98 * Return 1 if float or double arg is an infinity, else 0.
100 * X is evaluated more than once.
101 * This implementation may set the underflow flag if |X| is very small;
102 * it really can't be implemented correctly (& easily) before C99.
103 * Override in pyconfig.h if you have a better spelling on your platform.
104 * Note: PC/pyconfig.h defines Py_IS_INFINITY as _isinf
106 #ifndef Py_IS_INFINITY
108 #define Py_IS_INFINITY(X) isinf(X)
110 #define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
115 * Return 1 if float or double arg is neither infinite nor NAN, else 0.
116 * Some compilers (e.g. VisualStudio) have intrisics for this, so a special
117 * macro for this particular test is useful
118 * Note: PC/pyconfig.h defines Py_IS_FINITE as _finite
122 #define Py_IS_FINITE(X) finite(X)
124 #define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
128 /* HUGE_VAL is supposed to expand to a positive double infinity. Python
129 * uses Py_HUGE_VAL instead because some platforms are broken in this
130 * respect. We used to embed code in pyport.h to try to worm around that,
131 * but different platforms are broken in conflicting ways. If you're on
132 * a platform where HUGE_VAL is defined incorrectly, fiddle your Python
133 * config to #define Py_HUGE_VAL to something that works on your platform.
136 #define Py_HUGE_VAL HUGE_VAL
140 * A value that evaluates to a NaN. On IEEE 754 platforms INF*0 or
141 * INF/INF works. Define Py_NO_NAN in pyconfig.h if your platform
142 * doesn't support NaNs.
144 #if !defined(Py_NAN) && !defined(Py_NO_NAN)
145 #define Py_NAN (Py_HUGE_VAL * 0.)
149 * Return 1 iff a libm function overflowed. Set errno to 0 before calling
150 * a libm function, and invoke this macro after, passing the function
153 * This isn't reliable. C99 no longer requires libm to set errno under
154 * any exceptional condition, but does require +- HUGE_VAL return
155 * values on overflow. A 754 box *probably* maps HUGE_VAL to a
156 * double infinity, and we're cool if that's so, unless the input
157 * was an infinity and an infinity is the expected result. A C89
158 * system sets errno to ERANGE, so we check for that too. We're
159 * out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or
160 * if the returned result is a NaN, or if a C89 box returns HUGE_VAL
161 * in non-overflow cases.
162 * X is evaluated more than once.
163 * Some platforms have better way to spell this, so expect some #ifdef'ery.
165 * OpenBSD uses 'isinf()' because a compiler bug on that platform causes
166 * the longer macro version to be mis-compiled. This isn't optimal, and
167 * should be removed once a newer compiler is available on that platform.
168 * The system that had the failure was running OpenBSD 3.2 on Intel, with
171 * According to Tim's checkin, the FreeBSD systems use isinf() to work
172 * around a FPE bug on that platform.
174 #if defined(__FreeBSD__) || defined(__OpenBSD__)
175 #define Py_OVERFLOWED(X) isinf(X)
177 #define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE || \
178 (X) == Py_HUGE_VAL || \
179 (X) == -Py_HUGE_VAL))
182 #endif /* Py_PYMATH_H */