Port fixes and features from upstream bytesize#12
Merged
Conversation
Bug fixes (from bytesize-rs/bytesize):
- parse: use exact integer arithmetic when the number has no fractional
part; f64's 53-bit mantissa silently rounded large byte counts
("9007199254740993B" parsed to ...992). Overflow now errors instead
of wrapping (bytesize#171, adapted: checked_mul + ParseError instead
of saturating)
- display/parse round-trip: the display prefix table already emitted
"16.0 EiB" for u64::MAX but the parser had no exa arms, so humanbyte
couldn't parse back its own output
Features:
- exabyte support: EB/EIB constants, Unit::ExaByte/ExbiByte, eb()/eib()
constructors
- iter::Sum for derived types (owned and by-ref)
- as_kb()/as_mib()/... float accessors on derived types
- Display now honors formatter precision as decimals ({:.2} gives
"1.50 KiB"); previously precision truncated the string ({:.2} gave
"1."). Width/alignment/fill preserved
- Unit gains Debug/Clone/Copy/PartialEq/Eq and #[non_exhaustive]
Not ported: their ln()-based unit-selection fix (bytesize#175) - our
integer-log display is already exact at boundaries
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.
Bugs fixed (both reproduced in humanbyte before fixing)
f64 precision loss parsing integer byte counts: any string with a unit suffix went through
f64, whose 53-bit mantissa rounds large counts —parse("9007199254740993B")returned...992. Integer-valued numbers now take an exactu64path. I diverged from upstream on overflow: theysaturating_mul, we returnParseError(silently clamping"20000 PB"tou64::MAXseems worse than erroring).Display/parse round-trip broken at the top of the range (found while comparing, not from upstream): our display prefix table always included
E, sou64::MAXdisplays as"16.0 EiB"— butUnithad no exa arms, so humanbyte couldn't parse its own output. Round-trip now covered by a test over both formats at every unit boundary.Features ported
EB/EIBconstants,Unit::ExaByte/ExbiByte,eb()/eib()constructorsiter::Sumfor derived types (owned and by-ref):sizes.iter().sum::<ByteScale>()as_kb(),as_mib(), etc.format!("{size:.2}")now means 2 decimals ("1.50 KiB"). PreviouslyFormatter::padinterpreted precision as string truncation, so{:.2}produced"1."— arguably a third bug. Width/alignment/fill still work and the existing alignment tests pass unchanged.UnitgainsDebug/Clone/Copy/PartialEq/Eqand#[non_exhaustive]