Repository navigation
Cap the fraction digit scaling factor in NumberFormat - #1086
Yusufihsangorgel wants to merge 4 commits into
Conversation
`pow(10, fractionDigits) as int` stops being usable once a caller asks for more digits than the platform integer handles. A 64 bit int wraps at `pow(10, 19)` and a double prints as `1e+21`, and either way those characters went into the formatted output. Once the wrapped factor reached zero, at 64 digits, format threw IntegerDivisionByZeroException instead. Cap the exponent at what the platform can scale by and print the rest of the digits as zeros.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where requesting a large number of fraction digits in NumberFormat caused integer overflow, leading to incorrect output or runtime exceptions on platforms like the VM and dart2wasm. By capping the scaling factor and handling excess digits as trailing zeros, the fix ensures stability and maintains output consistency for high-precision formatting requirements. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes an issue in NumberFormat where requesting a large number of fraction digits caused integer overflow or incorrect exponent notation representation, resulting in unrelated digits being printed. It introduces a platform-dependent limit on scaling digits (_maxScalingDigits) and appends any excess fraction digits as trailing zeros. Comprehensive tests have been added to verify this behavior across different limits. There are no review comments, so I have no feedback to provide.
Requesting a large number of fraction digits from
NumberFormatoverflows the integer scaling factor thatformatmultiplies the fraction by. The overflow used to fill the fraction with unrelated digits. From 64 digits up there was no output at all, just an integer division error on the VM and dart2wasm. This change caps the scaling factor at 10^18, the largest power of ten that fits a 64-bitint, and prints the remaining places as zeros. I kept the same cap whereintis a double and the factor could have gone two digits further, so a 19 or 20 digit request there can come out differently.Fixes #440