Fix converting JS floating-point numbers to long (fix #228).

This commit is contained in:
Alexey Andreev 2016-11-04 14:12:51 +03:00
parent 6f5c6cd66e
commit daf5ada5c6
2 changed files with 8 additions and 1 deletions

View File

@ -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) {

View File

@ -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;
}