Correctly handle negative values

This commit is contained in:
Michael Droettboom 2018-10-03 08:15:00 -04:00
parent 1eb30ce4b3
commit cb1d7da166
2 changed files with 3 additions and 1 deletions

View File

@ -134,7 +134,7 @@ _python2js(PyObject* x, PyObject* map)
// Since Javascript doesn't support > 32-bit ints, use floats
// when the Python int gets too large. This will lose precision,
// but is less problematic than truncation.
if ((unsigned long)x_long > 0x7fffffff) {
if (labs(x_long) > 0x7fffffff) {
PyObject* py_float = PyNumber_Float(x);
if (py_float == NULL) {
return HW_ERROR;

View File

@ -63,6 +63,8 @@ def test_python2js_long_ints(selenium):
assert selenium.run('2**31') == 2**31
assert selenium.run('2**30 - 1 + 2**30') == (2**30 - 1 + 2**30)
assert selenium.run('2**32 / 2**4') == (2**32 / 2**4)
assert selenium.run('-2**30') == -2**30
assert selenium.run('-2**31') == -2**31
def test_pythonexc2js(selenium):