Commit 20362a82 authored by Alex Martelli's avatar Alex Martelli

x**2 should about equal x*x (including for a float x such that the result is

inf) but didn't; added a test to test_float to verify that, and ignored the
ERANGE value for errno in the pow operation to make the new test pass (with
help from Marilyn Davis at the Google Python Sprint -- thanks!).
parent 29bef0bb
......@@ -99,12 +99,25 @@ class IEEEFormatTestCase(unittest.TestCase):
('<f', LE_FLOAT_NAN)]:
struct.unpack(fmt, data)
# on an IEEE platform, "overflowing" operations produce infinity
class IEEEOperationsTestCase(unittest.TestCase):
if float.__getformat__("double").startswith("IEEE"):
def test_double_infinity(self):
big = 4.8e159
pro = big*big
self.assertEquals(repr(pro), 'inf')
sqr = big**2
self.assertEquals(repr(sqr), 'inf')
def test_main():
test_support.run_unittest(
FormatFunctionsTestCase,
UnknownFormatTestCase,
IEEEFormatTestCase)
IEEEFormatTestCase,
IEEEOperationsTestCase,
)
if __name__ == '__main__':
test_main()
......@@ -821,12 +821,12 @@ float_pow(PyObject *v, PyObject *w, PyObject *z)
ix = pow(iv, iw);
PyFPE_END_PROTECT(ix)
Py_ADJUST_ERANGE1(ix);
if (errno != 0) {
/* we need to ignore ERANGE here and just return inf */
if (errno != 0 && errno != ERANGE) {
/* We don't expect any errno value other than ERANGE, but
* the range of libm bugs appears unbounded.
*/
PyErr_SetFromErrno(errno == ERANGE ? PyExc_OverflowError :
PyExc_ValueError);
PyErr_SetFromErrno(PyExc_ValueError);
return NULL;
}
return PyFloat_FromDouble(ix);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment