Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ LongPrototype.divide = function divide(divisor) {
// positive number, due to two's complement.
if (
!this.unsigned &&
this.low === 0 &&
this.high === -0x80000000 &&
divisor.low === -1 &&
divisor.high === -1
Expand Down
17 changes: 17 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ var tests = [
assert.strictEqual(longVal.toString(), Long.MIN_VALUE.toString());
},

function testSignedNegHighWordDivNegOne() {
// A negative dividend whose high word is 0x80000000 but whose low word is
// non-zero must negate correctly when divided by -1. Only the exact
// MIN_VALUE / -1 is a true two's-complement overflow.
assert.strictEqual(
Long.fromString("-9223372036854775807").div(Long.fromInt(-1)).toString(),
"9223372036854775807",
);
assert.strictEqual(
Long.fromString("-9223372036854775296").div(Long.fromInt(-1)).toString(),
"9223372036854775296",
);
// The exact MIN_VALUE / -1 overflow still wraps to MIN_VALUE.
var overflow = Long.MIN_VALUE.div(Long.fromInt(-1));
assert.strictEqual(overflow.toString(), Long.MIN_VALUE.toString());
},

function testUnsignedMsbUnsigned() {
var longVal = Long.UONE.shiftLeft(63);
assert.strictEqual(longVal.notEquals(Long.MIN_VALUE), true);
Expand Down