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