fix: carry suffix when rounding pushes file_size mantissa to base#761
Open
patchwright wants to merge 1 commit into
Open
fix: carry suffix when rounding pushes file_size mantissa to base#761patchwright wants to merge 1 commit into
patchwright wants to merge 1 commit into
Conversation
The suffix is selected from the raw byte count before formatting. When the formatted mantissa rounds up to base (e.g. 999,999 bytes is 999.999 KB, formatted as "1000.0 KB"), no carry logic existed. After formatting, check whether the result is >= base; if so and a larger suffix is available, step up one suffix so the output reads "1.0 MB" instead of "1000.0 MB". Adds three regression cases to test_file_size covering the boundary for KB->MB, MB->GB, and GB->TB in decimal mode.
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.
Problem
file_size(999999)returns'1000.0 KB'instead of'1.0 MB'.The suffix is chosen from the raw byte count (before formatting), but the
formattingpattern rounds the mantissa afterward. When rounding pushes the mantissa tobase(e.g. 999,999 / 1000 = 999.999 → "1000.0"), the function keeps the smaller suffix.Same with
999,999,999→'1000.0 MB'(should be'1.0 GB').Fix
After computing the formatted string, check whether
float(formatted) >= base. If true and a larger suffix is available, step up one suffix. The formulabyte_size / unitgives the value in the next unit becauseunit = base**(i+2)is also the conversion factor for suffixi+1.Tests
Added three regression cases (KB→MB, MB→GB, GB→TB boundaries) to
test_file_size.