mirror of https://github.com/pyodide/pyodide.git
Correctly handle negative values
This commit is contained in:
parent
1eb30ce4b3
commit
cb1d7da166
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue