Repository navigation
Conversation
1,048,575 B is 1023.999 KiB and was shown as "1024.0 KiB". After
picking the unit, check whether the value rounds to a whole unit at the
requested precision and, if so, show it in the next unit ("1.0 MiB").
Fixes bytesize-rs#212
This branch has not been deployed
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 #212.
After the unit is picked, the value is rounded to the display precision. If that rounding reaches a whole unit (1023.999 KiB →
1024.0), the value is now shown in the next unit:1024.0 KiB1.0 MiB1000.0 kB1.0 MB1024.0 MiB1.0 GiB1024.0K1.0M{:.0}1024 KiB1 MiB{:.3}1023.999 KiB1023.999 KiB(no change)The check is
value >= unit - 0.5 * 10^-precision, so it follows the precision the caller asks for. It never goes past the largest prefix (u64::MAX is 16 EiB, so it can't reach that anyway).The existing
display_matches_just_below_pebi_boundarytest expected"1024.0 TiB"for1024^5 - 1bytes; it now expects"1.0 PiB". std and no_std still pick the same unit.Tests: two new tests (
rounding_carries_into_next_unit,rounding_carry_honors_precision) plus the updated one fail on master and pass here.cargo test(default,--no-default-features,--all-features), clippy, andcargo +nightly fmt --checkare clean. I also ran 2M random sizes throughiec()andsi()and checked that no output shows a number >= the unit.