Mercurial > cpython-lru_cache-weakref
view Python/pymath.c @ 64209:dfd0229748ef 2.7
Merged revisions 84239 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r84239 | antoine.pitrou | 2010-08-21 21:09:32 +0200 (sam., 21 août 2010) | 4 lines
Issue #9617: Signals received during a low-level write operation aren't
ignored by the buffered IO layer anymore.
........
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sat, 21 Aug 2010 19:17:25 +0000 |
| parents | fd25030223b0 |
| children | b36cb4602e21 |
line wrap: on
line source
#include "Python.h" #ifdef X87_DOUBLE_ROUNDING /* On x86 platforms using an x87 FPU, this function is called from the Py_FORCE_DOUBLE macro (defined in pymath.h) to force a floating-point number out of an 80-bit x87 FPU register and into a 64-bit memory location, thus rounding from extended precision to double precision. */ double _Py_force_double(double x) { volatile double y; y = x; return y; } #endif #ifdef HAVE_GCC_ASM_FOR_X87 /* inline assembly for getting and setting the 387 FPU control word on gcc/x86 */ unsigned short _Py_get_387controlword(void) { unsigned short cw; __asm__ __volatile__ ("fnstcw %0" : "=m" (cw)); return cw; } void _Py_set_387controlword(unsigned short cw) { __asm__ __volatile__ ("fldcw %0" : : "m" (cw)); } #endif #ifndef HAVE_HYPOT double hypot(double x, double y) { double yx; x = fabs(x); y = fabs(y); if (x < y) { double temp = x; x = y; y = temp; } if (x == 0.) return 0.; else { yx = y/x; return x*sqrt(1.+yx*yx); } } #endif /* HAVE_HYPOT */ #ifndef HAVE_COPYSIGN double copysign(double x, double y) { /* use atan2 to distinguish -0. from 0. */ if (y > 0. || (y == 0. && atan2(y, -1.) > 0.)) { return fabs(x); } else { return -fabs(x); } } #endif /* HAVE_COPYSIGN */ #ifndef HAVE_ROUND double round(double x) { double absx, y; absx = fabs(x); y = floor(absx); if (absx - y >= 0.5) y += 1.0; return copysign(y, x); } #endif /* HAVE_ROUND */
