Commit 299ad116 authored by Robert Bradshaw's avatar Robert Bradshaw

Avoid too large shift on LLP64 systems.

This fixes #1562
parent 4924bd9c
...@@ -577,7 +577,7 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO ...@@ -577,7 +577,7 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
x += ((x != 0) & ((x ^ b) < 0)) * b; x += ((x != 0) & ((x ^ b) < 0)) * b;
return PyInt_FromLong(x); return PyInt_FromLong(x);
{{elif op == 'TrueDivide'}} {{elif op == 'TrueDivide'}}
if (8 * sizeof(long) <= 53 || likely(labs({{ival}}) <= (1L << 53))) { if (8 * sizeof(long) <= 53 || likely(labs({{ival}}) <= ((PY_LONG_LONG)1 << 53))) {
return PyFloat_FromDouble((double)a / (double)b); return PyFloat_FromDouble((double)a / (double)b);
} }
// let Python do the rounding // let Python do the rounding
...@@ -667,7 +667,7 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO ...@@ -667,7 +667,7 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYTHO
x = a % b; x = a % b;
x += ((x != 0) & ((x ^ b) < 0)) * b; x += ((x != 0) & ((x ^ b) < 0)) * b;
{{elif op == 'TrueDivide'}} {{elif op == 'TrueDivide'}}
if ((8 * sizeof(long) <= 53 || likely(labs({{ival}}) <= (1L << 53))) if ((8 * sizeof(long) <= 53 || likely(labs({{ival}}) <= ((PY_LONG_LONG)1 << 53)))
|| __Pyx_sst_abs(size) <= 52 / PyLong_SHIFT) { || __Pyx_sst_abs(size) <= 52 / PyLong_SHIFT) {
return PyFloat_FromDouble((double)a / (double)b); return PyFloat_FromDouble((double)a / (double)b);
} }
...@@ -812,7 +812,7 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, dou ...@@ -812,7 +812,7 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, dou
if (8 * sizeof(unsigned long) > {{_size}} * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || ({{_size-1}} * PyLong_SHIFT < 53))) { if (8 * sizeof(unsigned long) > {{_size}} * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || ({{_size-1}} * PyLong_SHIFT < 53))) {
{{fval}} = (double) {{pylong_join(_size, 'digits')}}; {{fval}} = (double) {{pylong_join(_size, 'digits')}};
// let CPython do its own float rounding from 2**53 on (max. consecutive integer in double float) // let CPython do its own float rounding from 2**53 on (max. consecutive integer in double float)
if ((8 * sizeof(unsigned long) < 53) || ({{_size}} * PyLong_SHIFT < 53) || ({{fval}} < (double) (1L<<53))) { if ((8 * sizeof(unsigned long) < 53) || ({{_size}} * PyLong_SHIFT < 53) || ({{fval}} < (double) ((PY_LONG_LONG)1 << 53))) {
if (size == {{-_size}}) if (size == {{-_size}})
{{fval}} = -{{fval}}; {{fval}} = -{{fval}};
break; break;
......
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