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