diff --git a/core/src/main/resources/org/teavm/backend/javascript/runtime.js b/core/src/main/resources/org/teavm/backend/javascript/runtime.js index 25067354c..4288b39eb 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/backend/javascript/runtime.js @@ -621,7 +621,7 @@ function Long_fromNumber(val) { if (val >= 0) { return new Long(val | 0, (val / 0x100000000) | 0); } else { - return new Long(val | 0, (-(Math.abs(val) / 0x100000000) - 1) | 0); + return Long_neg(new Long(-val | 0, (-val / 0x100000000) | 0)); } } function Long_toNumber(val) { diff --git a/tests/src/test/java/org/teavm/vm/LongTest.java b/tests/src/test/java/org/teavm/vm/LongTest.java index 397be4a8b..e3bb3bc5f 100644 --- a/tests/src/test/java/org/teavm/vm/LongTest.java +++ b/tests/src/test/java/org/teavm/vm/LongTest.java @@ -49,6 +49,13 @@ public class LongTest { assertEquals(2971215073L, a + b); } + @Test + public void smallLongDivision() { + long a = id(-1); + long b = 3; + assertEquals(0, a / b); + } + private static long id(long value) { return value; }