annotate DEPENDENCIES/mingw32/Python27/include/pymath.h @ 118:770eb830ec19 emscripten

Typo fix
author Chris Cannam
date Wed, 18 May 2016 16:14:08 +0100
parents 2a2c65a20a8b
children
rev   line source
Chris@87 1 #ifndef Py_PYMATH_H
Chris@87 2 #define Py_PYMATH_H
Chris@87 3
Chris@87 4 #include "pyconfig.h" /* include for defines */
Chris@87 5
Chris@87 6 /**************************************************************************
Chris@87 7 Symbols and macros to supply platform-independent interfaces to mathematical
Chris@87 8 functions and constants
Chris@87 9 **************************************************************************/
Chris@87 10
Chris@87 11 /* Python provides implementations for copysign, round and hypot in
Chris@87 12 * Python/pymath.c just in case your math library doesn't provide the
Chris@87 13 * functions.
Chris@87 14 *
Chris@87 15 *Note: PC/pyconfig.h defines copysign as _copysign
Chris@87 16 */
Chris@87 17 #ifndef HAVE_COPYSIGN
Chris@87 18 extern double copysign(double, double);
Chris@87 19 #endif
Chris@87 20
Chris@87 21 #ifndef HAVE_ROUND
Chris@87 22 extern double round(double);
Chris@87 23 #endif
Chris@87 24
Chris@87 25 #ifndef HAVE_HYPOT
Chris@87 26 extern double hypot(double, double);
Chris@87 27 #endif
Chris@87 28
Chris@87 29 /* extra declarations */
Chris@87 30 #ifndef _MSC_VER
Chris@87 31 #ifndef __STDC__
Chris@87 32 extern double fmod (double, double);
Chris@87 33 extern double frexp (double, int *);
Chris@87 34 extern double ldexp (double, int);
Chris@87 35 extern double modf (double, double *);
Chris@87 36 extern double pow(double, double);
Chris@87 37 #endif /* __STDC__ */
Chris@87 38 #endif /* _MSC_VER */
Chris@87 39
Chris@87 40 #ifdef _OSF_SOURCE
Chris@87 41 /* OSF1 5.1 doesn't make these available with XOPEN_SOURCE_EXTENDED defined */
Chris@87 42 extern int finite(double);
Chris@87 43 extern double copysign(double, double);
Chris@87 44 #endif
Chris@87 45
Chris@87 46 /* High precision defintion of pi and e (Euler)
Chris@87 47 * The values are taken from libc6's math.h.
Chris@87 48 */
Chris@87 49 #ifndef Py_MATH_PIl
Chris@87 50 #define Py_MATH_PIl 3.1415926535897932384626433832795029L
Chris@87 51 #endif
Chris@87 52 #ifndef Py_MATH_PI
Chris@87 53 #define Py_MATH_PI 3.14159265358979323846
Chris@87 54 #endif
Chris@87 55
Chris@87 56 #ifndef Py_MATH_El
Chris@87 57 #define Py_MATH_El 2.7182818284590452353602874713526625L
Chris@87 58 #endif
Chris@87 59
Chris@87 60 #ifndef Py_MATH_E
Chris@87 61 #define Py_MATH_E 2.7182818284590452354
Chris@87 62 #endif
Chris@87 63
Chris@87 64 /* On x86, Py_FORCE_DOUBLE forces a floating-point number out of an x87 FPU
Chris@87 65 register and into a 64-bit memory location, rounding from extended
Chris@87 66 precision to double precision in the process. On other platforms it does
Chris@87 67 nothing. */
Chris@87 68
Chris@87 69 /* we take double rounding as evidence of x87 usage */
Chris@87 70 #ifndef Py_FORCE_DOUBLE
Chris@87 71 # ifdef X87_DOUBLE_ROUNDING
Chris@87 72 PyAPI_FUNC(double) _Py_force_double(double);
Chris@87 73 # define Py_FORCE_DOUBLE(X) (_Py_force_double(X))
Chris@87 74 # else
Chris@87 75 # define Py_FORCE_DOUBLE(X) (X)
Chris@87 76 # endif
Chris@87 77 #endif
Chris@87 78
Chris@87 79 #ifdef HAVE_GCC_ASM_FOR_X87
Chris@87 80 PyAPI_FUNC(unsigned short) _Py_get_387controlword(void);
Chris@87 81 PyAPI_FUNC(void) _Py_set_387controlword(unsigned short);
Chris@87 82 #endif
Chris@87 83
Chris@87 84 /* Py_IS_NAN(X)
Chris@87 85 * Return 1 if float or double arg is a NaN, else 0.
Chris@87 86 * Caution:
Chris@87 87 * X is evaluated more than once.
Chris@87 88 * This may not work on all platforms. Each platform has *some*
Chris@87 89 * way to spell this, though -- override in pyconfig.h if you have
Chris@87 90 * a platform where it doesn't work.
Chris@87 91 * Note: PC/pyconfig.h defines Py_IS_NAN as _isnan
Chris@87 92 */
Chris@87 93 #ifndef Py_IS_NAN
Chris@87 94 #if defined HAVE_DECL_ISNAN && HAVE_DECL_ISNAN == 1
Chris@87 95 #define Py_IS_NAN(X) isnan(X)
Chris@87 96 #else
Chris@87 97 #define Py_IS_NAN(X) ((X) != (X))
Chris@87 98 #endif
Chris@87 99 #endif
Chris@87 100
Chris@87 101 /* Py_IS_INFINITY(X)
Chris@87 102 * Return 1 if float or double arg is an infinity, else 0.
Chris@87 103 * Caution:
Chris@87 104 * X is evaluated more than once.
Chris@87 105 * This implementation may set the underflow flag if |X| is very small;
Chris@87 106 * it really can't be implemented correctly (& easily) before C99.
Chris@87 107 * Override in pyconfig.h if you have a better spelling on your platform.
Chris@87 108 * Py_FORCE_DOUBLE is used to avoid getting false negatives from a
Chris@87 109 * non-infinite value v sitting in an 80-bit x87 register such that
Chris@87 110 * v becomes infinite when spilled from the register to 64-bit memory.
Chris@87 111 * Note: PC/pyconfig.h defines Py_IS_INFINITY as _isinf
Chris@87 112 */
Chris@87 113 #ifndef Py_IS_INFINITY
Chris@87 114 # if defined HAVE_DECL_ISINF && HAVE_DECL_ISINF == 1
Chris@87 115 # define Py_IS_INFINITY(X) isinf(X)
Chris@87 116 # else
Chris@87 117 # define Py_IS_INFINITY(X) ((X) && \
Chris@87 118 (Py_FORCE_DOUBLE(X)*0.5 == Py_FORCE_DOUBLE(X)))
Chris@87 119 # endif
Chris@87 120 #endif
Chris@87 121
Chris@87 122 /* Py_IS_FINITE(X)
Chris@87 123 * Return 1 if float or double arg is neither infinite nor NAN, else 0.
Chris@87 124 * Some compilers (e.g. VisualStudio) have intrisics for this, so a special
Chris@87 125 * macro for this particular test is useful
Chris@87 126 * Note: PC/pyconfig.h defines Py_IS_FINITE as _finite
Chris@87 127 */
Chris@87 128 #ifndef Py_IS_FINITE
Chris@87 129 #if defined HAVE_DECL_ISFINITE && HAVE_DECL_ISFINITE == 1
Chris@87 130 #define Py_IS_FINITE(X) isfinite(X)
Chris@87 131 #elif defined HAVE_FINITE
Chris@87 132 #define Py_IS_FINITE(X) finite(X)
Chris@87 133 #else
Chris@87 134 #define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
Chris@87 135 #endif
Chris@87 136 #endif
Chris@87 137
Chris@87 138 /* HUGE_VAL is supposed to expand to a positive double infinity. Python
Chris@87 139 * uses Py_HUGE_VAL instead because some platforms are broken in this
Chris@87 140 * respect. We used to embed code in pyport.h to try to worm around that,
Chris@87 141 * but different platforms are broken in conflicting ways. If you're on
Chris@87 142 * a platform where HUGE_VAL is defined incorrectly, fiddle your Python
Chris@87 143 * config to #define Py_HUGE_VAL to something that works on your platform.
Chris@87 144 */
Chris@87 145 #ifndef Py_HUGE_VAL
Chris@87 146 #define Py_HUGE_VAL HUGE_VAL
Chris@87 147 #endif
Chris@87 148
Chris@87 149 /* Py_NAN
Chris@87 150 * A value that evaluates to a NaN. On IEEE 754 platforms INF*0 or
Chris@87 151 * INF/INF works. Define Py_NO_NAN in pyconfig.h if your platform
Chris@87 152 * doesn't support NaNs.
Chris@87 153 */
Chris@87 154 #if !defined(Py_NAN) && !defined(Py_NO_NAN)
Chris@87 155 #define Py_NAN (Py_HUGE_VAL * 0.)
Chris@87 156 #endif
Chris@87 157
Chris@87 158 /* Py_OVERFLOWED(X)
Chris@87 159 * Return 1 iff a libm function overflowed. Set errno to 0 before calling
Chris@87 160 * a libm function, and invoke this macro after, passing the function
Chris@87 161 * result.
Chris@87 162 * Caution:
Chris@87 163 * This isn't reliable. C99 no longer requires libm to set errno under
Chris@87 164 * any exceptional condition, but does require +- HUGE_VAL return
Chris@87 165 * values on overflow. A 754 box *probably* maps HUGE_VAL to a
Chris@87 166 * double infinity, and we're cool if that's so, unless the input
Chris@87 167 * was an infinity and an infinity is the expected result. A C89
Chris@87 168 * system sets errno to ERANGE, so we check for that too. We're
Chris@87 169 * out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or
Chris@87 170 * if the returned result is a NaN, or if a C89 box returns HUGE_VAL
Chris@87 171 * in non-overflow cases.
Chris@87 172 * X is evaluated more than once.
Chris@87 173 * Some platforms have better way to spell this, so expect some #ifdef'ery.
Chris@87 174 *
Chris@87 175 * OpenBSD uses 'isinf()' because a compiler bug on that platform causes
Chris@87 176 * the longer macro version to be mis-compiled. This isn't optimal, and
Chris@87 177 * should be removed once a newer compiler is available on that platform.
Chris@87 178 * The system that had the failure was running OpenBSD 3.2 on Intel, with
Chris@87 179 * gcc 2.95.3.
Chris@87 180 *
Chris@87 181 * According to Tim's checkin, the FreeBSD systems use isinf() to work
Chris@87 182 * around a FPE bug on that platform.
Chris@87 183 */
Chris@87 184 #if defined(__FreeBSD__) || defined(__OpenBSD__)
Chris@87 185 #define Py_OVERFLOWED(X) isinf(X)
Chris@87 186 #else
Chris@87 187 #define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE || \
Chris@87 188 (X) == Py_HUGE_VAL || \
Chris@87 189 (X) == -Py_HUGE_VAL))
Chris@87 190 #endif
Chris@87 191
Chris@87 192 #endif /* Py_PYMATH_H */