-
-
Notifications
You must be signed in to change notification settings - Fork 625
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
Fix big number accuracy #2276
Fix big number accuracy #2276
Conversation
3ccf7e4
to
a345aed
Compare
a345aed
to
0fe1ce3
Compare
} | ||
return sign === -1 ? `-${str}` : str; | ||
} | ||
if (numDigits > 16) { |
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.
dead code?
cc @wellwelwel @sidorares this was a pretty critical bug that caused data corruption for us, would love to contribute the fix to upstream |
@KunZhou-at, in fact the
I couldn't understand the issue, could you show an example where this would fail? It would be great if we could add a test to cover this possible failure as well 🙋🏻♂️ |
@wellwelwel thanks for taking a look! Basically my change is from
to
There are numbers larger than I updated the test to only return strings for numbers above |
@wellwelwel I still think this is a critical bug that can cause database corruption, but closing since it's not getting attention. Feel free to open and I can resolve the conflicts if that changes. |
Previously, big numbers were sometimes returned as number instead of string even if the number is larger than
Number.MAX_SAFE_INTEGER
or smaller thanNumber.MIN_SAFE_INTEGER
. The behavior was conditional on the equality ofbigNumber.toString() === fullAccuracyNumberInString
. However, the number may not be at full accuracy: for many big numbersBigInt(bigNumber).toString() !== bigNumber.toString()
, e.g.,99000001013466380