Commit cb1d7da1 authored by Michael Droettboom's avatar Michael Droettboom

Correctly handle negative values

parent 1eb30ce4
......@@ -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;
......
......@@ -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):
......
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