Commit 1c4475d9 authored by Stefan Behnel's avatar Stefan Behnel

optimise 2-digit PyLong case for float +/- operator

--HG--
extra : amend_source : 7d848b95b73159432b1eb94e238006dda0bd6e32
parent 8dde86f6
......@@ -600,6 +600,12 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, dou
case -1: {{fval}} = -(double)((PyLongObject*){{pyval}})->ob_digit[0]; break;
case 0: {{fval}} = 0.0; break;
case 1: {{fval}} = (double)((PyLongObject*){{pyval}})->ob_digit[0]; break;
case 2:
if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
{{fval}} = (double) ((((unsigned long)((PyLongObject*){{pyval}})->ob_digit[1]) << PyLong_SHIFT) | ((PyLongObject*){{pyval}})->ob_digit[0]);
break;
}
// fall through if two platform digits don't fit into a double
default: {{fval}} = PyLong_AsDouble({{pyval}});
if (unlikely({{fval}} == -1 && PyErr_Occurred())) return NULL;
break;
......
......@@ -131,6 +131,12 @@ def add_1f_x(x):
2.0
>>> add_1f_x(-1)
0.0
>>> 1.0 + 2**52
4503599627370497.0
>>> add_1f_x(2**52)
4503599627370497.0
>>> add_1f_x(2**60) == 1.0 + 2**60 or add_1f_x(2**60)
True
>>> add_1f_x(1.5)
2.5
>>> add_1f_x(-1.5)
......
......@@ -71,10 +71,12 @@ def sub_x_1f(x):
0.0
>>> sub_x_1f(-1)
-2.0
>>> 2**50 - 1.0
1125899906842623.0
>>> sub_x_1f(2**50)
1125899906842623.0
>>> 2**52 - 1.0
4503599627370495.0
>>> sub_x_1f(2**52)
4503599627370495.0
>>> sub_x_1f(2**60) == 2**60 - 1.0 or sub_x_1f(2**60)
True
>>> sub_x_1f(1.5)
0.5
>>> sub_x_1f(-1.5)
......@@ -146,6 +148,12 @@ def sub_1f_x(x):
2.0
>>> sub_1f_x(1)
0.0
>>> 1.0 - 2**52
-4503599627370495.0
>>> sub_1f_x(2**52)
-4503599627370495.0
>>> sub_1f_x(2**60) == 1.0 - 2**60 or sub_1f_x(2**60)
True
>>> sub_1f_x(1.5)
-0.5
>>> sub_1f_x(-1.5)
......
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