Skip to content

Commit 545900d

Browse files
committed
feat(long): replace long implementatin with long.js
There have been improvements on the original implementation since it was vendored in, including a wasm implementation. We will now track the community module.
1 parent 3c922ad commit 545900d

File tree

4 files changed

+90
-938
lines changed

4 files changed

+90
-938
lines changed

Diff for: lib/decimal128.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function divideu128(value) {
8989
_rem = _rem.shiftLeft(32);
9090
// Add the divided to _rem
9191
_rem = _rem.add(new Long(value.parts[i], 0));
92-
value.parts[i] = _rem.div(DIVISOR).low_;
92+
value.parts[i] = _rem.div(DIVISOR).low;
9393
_rem = _rem.modulo(DIVISOR);
9494
}
9595

@@ -126,15 +126,15 @@ function multiply64x2(left, right) {
126126

127127
function lessThan(left, right) {
128128
// Make values unsigned
129-
const uhleft = left.high_ >>> 0;
130-
const uhright = right.high_ >>> 0;
129+
const uhleft = left.high >>> 0;
130+
const uhright = right.high >>> 0;
131131

132132
// Compare high bits first
133133
if (uhleft < uhright) {
134134
return true;
135135
} else if (uhleft === uhright) {
136-
const ulleft = left.low_ >>> 0;
137-
const ulright = right.low_ >>> 0;
136+
const ulleft = left.low >>> 0;
137+
const ulright = right.low >>> 0;
138138
if (ulleft < ulright) return true;
139139
}
140140

@@ -153,7 +153,6 @@ function invalidErr(string, message) {
153153
* @return {Double}
154154
*/
155155
function Decimal128(bytes) {
156-
this._bsontype = 'Decimal128';
157156
this.bytes = bytes;
158157
}
159158

@@ -499,7 +498,7 @@ Decimal128.fromString = function(string) {
499498
significand.high
500499
.shiftRightUnsigned(49)
501500
.and(Long.fromNumber(1))
502-
.equals(Long.fromNumber)
501+
.equals(Long.fromNumber(1))
503502
) {
504503
// Encode '11' into bits 1 to 3
505504
dec.high = dec.high.or(Long.fromNumber(0x3).shiftLeft(61));
@@ -525,27 +524,27 @@ Decimal128.fromString = function(string) {
525524

526525
// Encode the low 64 bits of the decimal
527526
// Encode low bits
528-
buffer[index++] = dec.low.low_ & 0xff;
529-
buffer[index++] = (dec.low.low_ >> 8) & 0xff;
530-
buffer[index++] = (dec.low.low_ >> 16) & 0xff;
531-
buffer[index++] = (dec.low.low_ >> 24) & 0xff;
527+
buffer[index++] = dec.low.low & 0xff;
528+
buffer[index++] = (dec.low.low >> 8) & 0xff;
529+
buffer[index++] = (dec.low.low >> 16) & 0xff;
530+
buffer[index++] = (dec.low.low >> 24) & 0xff;
532531
// Encode high bits
533-
buffer[index++] = dec.low.high_ & 0xff;
534-
buffer[index++] = (dec.low.high_ >> 8) & 0xff;
535-
buffer[index++] = (dec.low.high_ >> 16) & 0xff;
536-
buffer[index++] = (dec.low.high_ >> 24) & 0xff;
532+
buffer[index++] = dec.low.high & 0xff;
533+
buffer[index++] = (dec.low.high >> 8) & 0xff;
534+
buffer[index++] = (dec.low.high >> 16) & 0xff;
535+
buffer[index++] = (dec.low.high >> 24) & 0xff;
537536

538537
// Encode the high 64 bits of the decimal
539538
// Encode low bits
540-
buffer[index++] = dec.high.low_ & 0xff;
541-
buffer[index++] = (dec.high.low_ >> 8) & 0xff;
542-
buffer[index++] = (dec.high.low_ >> 16) & 0xff;
543-
buffer[index++] = (dec.high.low_ >> 24) & 0xff;
539+
buffer[index++] = dec.high.low & 0xff;
540+
buffer[index++] = (dec.high.low >> 8) & 0xff;
541+
buffer[index++] = (dec.high.low >> 16) & 0xff;
542+
buffer[index++] = (dec.high.low >> 24) & 0xff;
544543
// Encode high bits
545-
buffer[index++] = dec.high.high_ & 0xff;
546-
buffer[index++] = (dec.high.high_ >> 8) & 0xff;
547-
buffer[index++] = (dec.high.high_ >> 16) & 0xff;
548-
buffer[index++] = (dec.high.high_ >> 24) & 0xff;
544+
buffer[index++] = dec.high.high & 0xff;
545+
buffer[index++] = (dec.high.high >> 8) & 0xff;
546+
buffer[index++] = (dec.high.high >> 16) & 0xff;
547+
buffer[index++] = (dec.high.high >> 24) & 0xff;
549548

550549
// Return the new Decimal128
551550
return new Decimal128(buffer);
@@ -682,7 +681,7 @@ Decimal128.prototype.toString = function() {
682681
// Peform the divide
683682
let result = divideu128(significand128);
684683
significand128 = result.quotient;
685-
least_digits = result.rem.low_;
684+
least_digits = result.rem.low;
686685

687686
// We now have the 9 least significant digits (in base 2).
688687
// Convert and output to string.
@@ -789,4 +788,5 @@ Decimal128.prototype.toJSON = function() {
789788
return { $numberDecimal: this.toString() };
790789
};
791790

791+
Object.defineProperty(Decimal128.prototype, '_bsontype', { value: 'Decimal128' });
792792
module.exports = Decimal128;

0 commit comments

Comments
 (0)