Repository navigation
metric: handle rounding carry at the quetta boundary - #485
Closed
mayur-dhavan wants to merge 2 commits into
Closed
mayur-dhavan wants to merge 2 commits into
mayur-dhavan wants to merge 2 commits into
Conversation
Remove unnecessary condition for rounding carry in number formatting.
Add test cases for rounding carry at quetta boundary.
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #423.
Problem
metric()absorbs a rounding carry (9999->10.0 k) by bumping the exponent, but the carry check was guarded byexponent < 30, so at the quetta boundary the mantissa gained a digit instead:Fix
Drop the
exponent < 30guard so the carry logic applies to every bucket, and when the bump pushes the exponent to 33 (past quetta, where no larger SI prefix exists), fall back toscientific(), matching the documented behavior for values beyond the prefix range. The negative-exponent side (quecto) already worked and is covered by a new regression case.Tests
Five new parametrized cases in
test_metric:9.996e30->10.0 Q,9.996e31->100 Q,9.996e32->1.00 x 10³³,9.999e-30->10.0 q,-9.996e31->-100 Q.tests/test_number.pypasses locally (246 passed) and the full suite passes except the pre-existingtest_benchmarks.pycollection errors, which require the optionalpytest-benchmarkplugin and fail identically on unmodified master.AI disclosure: this contribution was prepared with AI assistance (an automated coding agent acting on behalf of the author); the change and tests were validated locally against the project's test suite as described above.