Skip to content

Commit

Permalink
Alternative fix for int64toString (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpcstld committed Aug 29, 2022
1 parent 2062ff8 commit b54b84b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/runtime/spec/pb-long.spec.ts
@@ -1,4 +1,5 @@
import {PbLong, PbULong} from "../src";
import {int64toString} from "../src/goog-varint";


describe('PbULong', function () {
Expand Down Expand Up @@ -72,6 +73,13 @@ describe('PbULong', function () {
expect(ulong.lo).toBe(0);
});

it('int64toString should serialize the same was as BigInt.toString()', function () {
let ulong = PbULong.from(1661324400000);
expect(ulong.hi).toBe(386);
expect(ulong.lo).toBe(-827943552);
expect(ulong.toString()).toBe('1661324400000')
expect(int64toString(ulong.lo, ulong.hi)).toBe('1661324400000')
});
});


Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/goog-varint.ts
Expand Up @@ -178,7 +178,7 @@ export function int64toString(bitsLow: number, bitsHigh: number): string {
// Skip the expensive conversion if the number is small enough to use the
// built-in conversions.
if (bitsHigh <= 0x1FFFFF) {
return '' + (TWO_PWR_32_DBL * bitsHigh + bitsLow);
return '' + (TWO_PWR_32_DBL * bitsHigh + (bitsLow >>> 0));
}

// What this code is doing is essentially converting the input number from
Expand Down

0 comments on commit b54b84b

Please sign in to comment.