[Python-checkins] r60886 - in python/branches/trunk-math: Include/pystate.h Lib/test/test_complex.py Lib/test/test_contextlib.py Lib/test/test_float.py Modules/mathmodule.c Objects/complexobject.c Objects/floatobject.c Python/pystate.c
christian.heimes
python-checkins at python.org
Mon Feb 18 14:59:36 CET 2008
Author: christian.heimes
Date: Mon Feb 18 14:59:35 2008
New Revision: 60886
Modified:
python/branches/trunk-math/Include/pystate.h
python/branches/trunk-math/Lib/test/test_complex.py
python/branches/trunk-math/Lib/test/test_contextlib.py
python/branches/trunk-math/Lib/test/test_float.py
python/branches/trunk-math/Modules/mathmodule.c
python/branches/trunk-math/Objects/complexobject.c
python/branches/trunk-math/Objects/floatobject.c
python/branches/trunk-math/Python/pystate.c
Log:
Removed IEEE 754 context related code. Mark and I are going to write a proper PEP first.
Modified: python/branches/trunk-math/Include/pystate.h
==============================================================================
--- python/branches/trunk-math/Include/pystate.h (original)
+++ python/branches/trunk-math/Include/pystate.h Mon Feb 18 14:59:35 2008
@@ -44,12 +44,6 @@
/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
-typedef enum {
- PyIEEE_Python, /* Python standard mode */
- PyIEEE_754, /* IEEE 754 mode */
- PyIEEE_Strict, /* strict Python mode */
-} PyIEEE_Mode;
-
/* The following values are used for 'what' for tracefunc functions: */
#define PyTrace_CALL 0
#define PyTrace_EXCEPTION 1
@@ -101,8 +95,6 @@
PyObject *async_exc; /* Asynchronous exception to raise */
long thread_id; /* Thread id where this tstate was created */
- PyIEEE_Mode float_ieee754; /* floating point operation behavior */
-
/* XXX signal handlers should also be here */
} PyThreadState;
@@ -197,11 +189,6 @@
/* hook for PyEval_GetFrame(), requested for Psyco */
PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame;
-/* IEEE floating op state */
-#define PyIEEE_GET() PyThreadState_GET()->float_ieee754
-PyAPI_FUNC(int) PyIEEE_GetState(void);
-PyAPI_FUNC(int) PyIEEE_SetState(int);
-
#ifdef __cplusplus
}
#endif
Modified: python/branches/trunk-math/Lib/test/test_complex.py
==============================================================================
--- python/branches/trunk-math/Lib/test/test_complex.py (original)
+++ python/branches/trunk-math/Lib/test/test_complex.py Mon Feb 18 14:59:35 2008
@@ -10,7 +10,6 @@
from random import random
from math import atan2, pi, isinf, isnan, copysign
-from contextlib import ieee754
INF = float("inf")
NAN = float("nan")
@@ -112,19 +111,6 @@
self.assertAlmostEqual(complex.__floordiv__(3+0j, 1.5+0j), 2)
self.assertRaises(ZeroDivisionError, complex.__floordiv__, 3+0j, 0+0j)
- def test_div_ieee754(self):
- with ieee754():
- self.assertInf(complex(1., 0) / complex(0.), 1, 0)
- self.assertInf(complex(-1., 0) / complex(0.), -1, 0)
- self.assertInf(complex(-1., 0) / complex(-0.), 1, 0)
- self.assertInf(complex(0, 1.) / complex(0.), 0, 1)
- self.assertInf(complex(0, -1.) / complex(0.), 0, -1)
- self.assertInf(complex(1., 1.) / complex(0.), 1, 1)
- self.assertInf(complex(1., -1.) / complex(0.), 1, -1)
- self.assertInf(complex(-1., 1.) / complex(0.), -1, 1)
- self.assertInf(complex(-1., -1.) / complex(0.), -1, -1)
- self.assertInf(complex(0.) / complex(0.), 0, 0)
-
def test_coerce(self):
self.assertRaises(OverflowError, complex.__coerce__, 1+1j, 1L<<10000)
Modified: python/branches/trunk-math/Lib/test/test_contextlib.py
==============================================================================
--- python/branches/trunk-math/Lib/test/test_contextlib.py (original)
+++ python/branches/trunk-math/Lib/test/test_contextlib.py Mon Feb 18 14:59:35 2008
@@ -331,25 +331,6 @@
return True
self.boilerPlate(lock, locked)
-class IEEE754TestCase(unittest.TestCase):
-
- def setUp(self):
- self.state = math.get_ieee754()
-
- def tearDown(self):
- math.set_ieee754(self.state)
-
- def test_ieee754(self):
- with ieee754():
- r1 = 42./0.
- r2 = -23./0.
- r3 = 0./0.
- self.assert_(math.isinf(r1))
- self.assert_(r1 > 0)
- self.assert_(math.isinf(r2))
- self.assert_(r2 < 0)
- self.assert_(math.isnan(r3))
-
# This is needed to make the test actually run under regrtest.py!
def test_main():
test_support.run_unittest(__name__)
Modified: python/branches/trunk-math/Lib/test/test_float.py
==============================================================================
--- python/branches/trunk-math/Lib/test/test_float.py (original)
+++ python/branches/trunk-math/Lib/test/test_float.py Mon Feb 18 14:59:35 2008
@@ -217,77 +217,6 @@
self.failIf((0.).is_inf())
-class IEEE754TestCase(unittest.TestCase):
-
- def setUp(self):
- self.old_state = math.set_ieee754(math.IEEE_754)
-
- def tearDown(self):
- math.set_ieee754(self.old_state)
-
- def test_div(self):
- self.assert_(isinf(2./0.))
- self.assert_(2./0. > 0)
- self.assert_(isinf(-2./0.))
- self.assert_(-2./0. < 0)
- self.assert_(isnan(0./0.))
-
- self.assertRaises(ZeroDivisionError, operator.floordiv, 1., 0.)
- self.assertRaises(ZeroDivisionError, operator.floordiv, 0., 0.)
- self.assertRaises(ZeroDivisionError, operator.div, 1, 0)
- self.assertRaises(ZeroDivisionError, operator.div, 0, 0)
-
- def test_mod(self):
- self.assert_(isinf(2. % 0.))
- self.assert_(2. % 0. > 0)
- self.assert_(isinf(-2. % 0.))
- self.assert_(-2. % 0. < 0)
- self.assert_(isnan(0. % 0.))
-
- self.assertRaises(ZeroDivisionError, operator.div, 0, 0)
- self.assertRaises(ZeroDivisionError, operator.div, 0, 0)
-
-class IEEEStrictTestCase(unittest.TestCase):
-
- def setUp(self):
- self.old_state = math.set_ieee754(math.IEEE_STRICT)
-
- def tearDown(self):
- math.set_ieee754(self.old_state)
-
- def value(self, op, *args):
- self.assertRaises(ValueError, op, *args)
-
- def overflow(self, op, *args):
- self.assertRaises(OverflowError, op, *args)
-
- def test_errors(self):
- self.overflow(operator.mul, 1E300, 1E300)
- self.overflow(operator.add, INF, 1)
- self.overflow(operator.sub, INF, 1)
- self.overflow(operator.div, INF, 1)
- self.overflow(operator.mul, INF, 1)
- self.overflow(operator.pow, INF, 1)
- self.value(operator.add, NAN, 1)
- self.value(operator.sub, NAN, 1)
- self.value(operator.div, NAN, 1)
- self.value(operator.mul, NAN, 1)
- self.value(operator.pow, NAN, 1)
- self.value(operator.mod, INF, 1)
- self.assertRaises(ZeroDivisionError, operator.floordiv, 1., 0.)
- self.assertRaises(ZeroDivisionError, operator.floordiv, 0., 0.)
- self.assertRaises(ZeroDivisionError, operator.div, 1, 0)
- self.assertRaises(ZeroDivisionError, operator.div, 0, 0)
-
- def test_fromstring(self):
- self.assertAlmostEqual(float("1E100"), 1E100)
- self.assertAlmostEqual(float("-1E308"), -1E308)
- self.overflow(float, "1E400")
- self.overflow(float, "inf")
- self.overflow(float, "-inf")
- self.value(float, "nan")
-
-
def test_main():
test_support.run_unittest(
FormatFunctionsTestCase,
@@ -295,8 +224,6 @@
IEEEFormatTestCase,
ReprTestCase,
InfNanTest,
- IEEE754TestCase,
- IEEEStrictTestCase
)
if __name__ == '__main__':
Modified: python/branches/trunk-math/Modules/mathmodule.c
==============================================================================
--- python/branches/trunk-math/Modules/mathmodule.c (original)
+++ python/branches/trunk-math/Modules/mathmodule.c Mon Feb 18 14:59:35 2008
@@ -610,34 +610,6 @@
"isinf(x) -> bool\n\
Checks if float x is infinite (positive or negative)");
-static PyObject *
-math_set_ieee754(PyObject *self, PyObject *arg)
-{
- long state = PyInt_AsLong(arg);
-
- if (state == -1 && PyErr_Occurred())
- return NULL;
- if (!(state == PyIEEE_Python || state == PyIEEE_754 ||
- state == PyIEEE_Strict)) {
- PyErr_Format(PyExc_ValueError, "Invalid state %ld", state);
- return NULL;
- }
-
- return PyInt_FromLong((long)PyIEEE_SetState(state));
-}
-
-PyDoc_STRVAR(math_set_ieee754_doc,
-"set_ieee754(int) -> int");
-
-static PyObject *
-math_get_ieee754(PyObject *self, PyObject *arg)
-{
- return PyInt_FromLong((long)PyIEEE_GetState());
-}
-
-PyDoc_STRVAR(math_get_ieee754_doc,
-"get_ieee754() -> int");
-
static PyMethodDef math_methods[] = {
{"acos", math_acos, METH_O, math_acos_doc},
{"acosh", math_acosh, METH_O, math_acosh_doc},
@@ -656,7 +628,6 @@
{"floor", math_floor, METH_O, math_floor_doc},
{"fmod", math_fmod, METH_VARARGS, math_fmod_doc},
{"frexp", math_frexp, METH_O, math_frexp_doc},
- {"get_ieee754", math_get_ieee754, METH_NOARGS, math_get_ieee754_doc},
{"hypot", math_hypot, METH_VARARGS, math_hypot_doc},
{"isinf", math_isinf, METH_O, math_isinf_doc},
{"isnan", math_isnan, METH_O, math_isnan_doc},
@@ -667,7 +638,6 @@
{"modf", math_modf, METH_O, math_modf_doc},
{"pow", math_pow, METH_VARARGS, math_pow_doc},
{"radians", math_radians, METH_O, math_radians_doc},
- {"set_ieee754", math_set_ieee754, METH_O, math_set_ieee754_doc},
{"sin", math_sin, METH_O, math_sin_doc},
{"sinh", math_sinh, METH_O, math_sinh_doc},
{"sqrt", math_sqrt, METH_O, math_sqrt_doc},
@@ -693,9 +663,6 @@
PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI));
PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
- PyModule_AddIntConstant(m, "IEEE_PYTHON", PyIEEE_Python);
- PyModule_AddIntConstant(m, "IEEE_754", PyIEEE_754);
- PyModule_AddIntConstant(m, "IEEE_STRICT", PyIEEE_Strict);
finally:
return;
Modified: python/branches/trunk-math/Objects/complexobject.c
==============================================================================
--- python/branches/trunk-math/Objects/complexobject.c (original)
+++ python/branches/trunk-math/Objects/complexobject.c Mon Feb 18 14:59:35 2008
@@ -121,26 +121,6 @@
}
Py_complex
-c_quot_ieee754(Py_complex a, Py_complex b)
-{
- /* IEEE 754 style division */
- if (b.real == 0. && b.imag == 0.) {
- /* Complex division by zero
- * - division of a complex w/o an imaginary part behaves like
- * float division: (x+0j)/(0+0j) == x/0
- * - (0+0j)/(0+0j) results in NAN
- * - for the remaining cases it's trying to do something
- * sensible while keeping the invariant abs(c/0) == inf
- */
- Py_complex quot;
- quot.real = copysign(Py_HUGE_VAL, b.real) * a.real;
- quot.imag = copysign(Py_HUGE_VAL, b.imag) * a.imag;
- return quot;
- }
- return c_quot(a, b);
-}
-
-Py_complex
c_pow(Py_complex a, Py_complex b)
{
Py_complex r;
@@ -540,10 +520,7 @@
PyFPE_START_PROTECT("complex_div", return 0)
errno = 0;
- if (PyIEEE_GET() == PyIEEE_754)
- quot = c_quot_ieee754(v->cval,w->cval);
- else
- quot = c_quot(v->cval,w->cval);
+ quot = c_quot(v->cval,w->cval);
PyFPE_END_PROTECT(quot)
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex division");
@@ -564,10 +541,7 @@
PyFPE_START_PROTECT("complex_classic_div", return 0)
errno = 0;
- if (PyIEEE_GET() == PyIEEE_754)
- quot = c_quot_ieee754(v->cval,w->cval);
- else
- quot = c_quot(v->cval,w->cval);
+ quot = c_quot(v->cval,w->cval);
PyFPE_END_PROTECT(quot)
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex division");
Modified: python/branches/trunk-math/Objects/floatobject.c
==============================================================================
--- python/branches/trunk-math/Objects/floatobject.c (original)
+++ python/branches/trunk-math/Objects/floatobject.c Mon Feb 18 14:59:35 2008
@@ -143,16 +143,6 @@
if ((free_list = fill_free_list()) == NULL)
return NULL;
}
- if (PyIEEE_GET() == PyIEEE_Strict) {
- if (Py_IS_NAN(fval)) {
- PyErr_SetString(PyExc_ValueError, "Not a Number");
- return NULL;
- }
- if (Py_IS_INFINITY(fval)) {
- PyErr_SetString(PyExc_OverflowError, "Infinity");
- return NULL;
- }
- }
/* Inline PyObject_New */
op = free_list;
free_list = (PyFloatObject *)Py_TYPE(op);
@@ -252,20 +242,10 @@
p++;
}
if (PyOS_strnicmp(p, "inf", 4) == 0) {
- if (PyIEEE_GET() == PyIEEE_Strict) {
- PyErr_SetString(PyExc_OverflowError,
- "Infinity");
- return NULL;
- }
Py_RETURN_INF(sign);
}
#ifdef Py_NAN
if(PyOS_strnicmp(p, "nan", 4) == 0) {
- if (PyIEEE_GET() == PyIEEE_Strict) {
- PyErr_SetString(PyExc_ValueError,
- "Not a Number");
- return NULL;
- }
Py_RETURN_NAN;
}
#endif
@@ -793,15 +773,9 @@
CONVERT_TO_DOUBLE(w, b);
#ifdef Py_NAN
if (b == 0.0) {
- if (PyIEEE_GET() == PyIEEE_Python) {
- PyErr_SetString(PyExc_ZeroDivisionError,
- "float division");
- return NULL;
- }
- else if (a == 0.)
- Py_RETURN_NAN;
- else
- Py_RETURN_INF(a);
+ PyErr_SetString(PyExc_ZeroDivisionError,
+ "float division");
+ return NULL;
}
#endif
PyFPE_START_PROTECT("divide", return 0)
@@ -821,15 +795,9 @@
return NULL;
#ifdef Py_NAN
if (b == 0.0) {
- if (PyIEEE_GET() == PyIEEE_Python) {
- PyErr_SetString(PyExc_ZeroDivisionError,
- "float division");
- return NULL;
- }
- else if (a == 0.)
- Py_RETURN_NAN;
- else
- Py_RETURN_INF(a);
+ PyErr_SetString(PyExc_ZeroDivisionError,
+ "float division");
+ return NULL;
}
#endif
PyFPE_START_PROTECT("divide", return 0)
@@ -847,15 +815,9 @@
CONVERT_TO_DOUBLE(w, wx);
#ifdef Py_NAN
if (wx == 0.0) {
- if (PyIEEE_GET() == PyIEEE_Python) {
- PyErr_SetString(PyExc_ZeroDivisionError,
- "float modulo");
- return NULL;
- }
- else if (vx == 0.)
- Py_RETURN_NAN;
- else
- Py_RETURN_INF(vx);
+ PyErr_SetString(PyExc_ZeroDivisionError,
+ "float modulo");
+ return NULL;
}
#endif
PyFPE_START_PROTECT("modulo", return 0)
@@ -1607,13 +1569,11 @@
_Py_NewReference(var); \
}
- state = PyIEEE_SetState(PyIEEE_Python);
#ifdef Py_NAN
static_float(PyFloat_NAN, Py_NAN);
#endif
static_float(PyFloat_PINF, Py_HUGE_VAL);
static_float(PyFloat_NINF, -Py_HUGE_VAL);
- PyIEEE_SetState(state);
#undef static_float
}
Modified: python/branches/trunk-math/Python/pystate.c
==============================================================================
--- python/branches/trunk-math/Python/pystate.c (original)
+++ python/branches/trunk-math/Python/pystate.c Mon Feb 18 14:59:35 2008
@@ -193,8 +193,6 @@
tstate->c_profileobj = NULL;
tstate->c_traceobj = NULL;
- tstate->float_ieee754 = PyIEEE_Python;
-
#ifdef WITH_THREAD
_PyGILState_NoteThreadState(tstate);
#endif
@@ -635,23 +633,6 @@
PyEval_SaveThread();
}
-int
-PyIEEE_GetState(void)
-{
- return PyThreadState_Get()->float_ieee754;
-}
-
-int
-PyIEEE_SetState(int state)
-{
- int old_state;
- PyThreadState *tstate = PyThreadState_Get();
-
- old_state = tstate->float_ieee754;
- tstate->float_ieee754 = state;
- return old_state;
-}
-
#ifdef __cplusplus
}
#endif
More information about the Python-checkins
mailing list