-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative fix for int64toString #367
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like the correct fix to me. Thanks!
@timostamm Could we publish a new version of the package on NPM with this fix? |
Of course, it's released in v2.8.1. |
This causes incorrect output on platforms w/o protobuf-ts/packages/runtime/spec/pb-long.spec.ts Lines 37 to 40 in 2f0ed59
protobuf-ts/packages/runtime/spec/pb-long.spec.ts Lines 109 to 112 in 2f0ed59
We can get the correct output if we modify the bitsLow = bitsLow >>> 0;
bitsHigh = bitsHigh >>> 0;
if (bitsHigh <= 0x1FFFFF) {
return '' + (TWO_PWR_32_DBL * bitsHigh + bitsLow);
} Alternatively we only cast if ((bitsHigh >>> 0) <= 0x1FFFFF) {
return '' + (TWO_PWR_32_DBL * bitsHigh + (bitsLow >>> 0));
} All the tests pass (both with and without BI support) using either approach. I'm not sure if one solution is preferable to the other. |
Summary
Borrowed from protocolbuffers/protobuf#8170, this PR is an alternative approach for #366. (I'm the colleague.)
The error in this optimization is that it incorrectly assumes that
bitsLow
is never negative, but that can occur when the highest bit is set due to 2s complement representation.Test Plan