ยปCore Development>Code coverage>Python/pymath.c

Python code coverage for Python/pymath.c

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