]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Python/pymath.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Python / pymath.c
CommitLineData
4710c53d 1#include "Python.h"\r
2\r
3#ifdef X87_DOUBLE_ROUNDING\r
4/* On x86 platforms using an x87 FPU, this function is called from the\r
5 Py_FORCE_DOUBLE macro (defined in pymath.h) to force a floating-point\r
6 number out of an 80-bit x87 FPU register and into a 64-bit memory location,\r
7 thus rounding from extended precision to double precision. */\r
8double _Py_force_double(double x)\r
9{\r
10 volatile double y;\r
11 y = x;\r
12 return y;\r
13}\r
14#endif\r
15\r
16#ifdef HAVE_GCC_ASM_FOR_X87\r
17\r
18/* inline assembly for getting and setting the 387 FPU control word on\r
19 gcc/x86 */\r
20\r
21unsigned short _Py_get_387controlword(void) {\r
22 unsigned short cw;\r
23 __asm__ __volatile__ ("fnstcw %0" : "=m" (cw));\r
24 return cw;\r
25}\r
26\r
27void _Py_set_387controlword(unsigned short cw) {\r
28 __asm__ __volatile__ ("fldcw %0" : : "m" (cw));\r
29}\r
30\r
31#endif\r
32\r
33\r
34#ifndef HAVE_HYPOT\r
35double hypot(double x, double y)\r
36{\r
37 double yx;\r
38\r
39 x = fabs(x);\r
40 y = fabs(y);\r
41 if (x < y) {\r
42 double temp = x;\r
43 x = y;\r
44 y = temp;\r
45 }\r
46 if (x == 0.)\r
47 return 0.;\r
48 else {\r
49 yx = y/x;\r
50 return x*sqrt(1.+yx*yx);\r
51 }\r
52}\r
53#endif /* HAVE_HYPOT */\r
54\r
55#ifndef HAVE_COPYSIGN\r
56double\r
57copysign(double x, double y)\r
58{\r
59 /* use atan2 to distinguish -0. from 0. */\r
60 if (y > 0. || (y == 0. && atan2(y, -1.) > 0.)) {\r
61 return fabs(x);\r
62 } else {\r
63 return -fabs(x);\r
64 }\r
65}\r
66#endif /* HAVE_COPYSIGN */\r
67\r
68#ifndef HAVE_ROUND\r
69double\r
70round(double x)\r
71{\r
72 double absx, y;\r
73 absx = fabs(x);\r
74 y = floor(absx);\r
75 if (absx - y >= 0.5)\r
76 y += 1.0;\r
77 return copysign(y, x);\r
78}\r
79#endif /* HAVE_ROUND */\r