Skip to content

Parse integer byte counts exactly in ParseBytes - #151

Open
sayantanmandal1 wants to merge 1 commit into
dustin:masterfrom
sayantanmandal1:parsebytes-exact-integers
Open

Parse integer byte counts exactly in ParseBytes#151
sayantanmandal1 wants to merge 1 commit into
dustin:masterfrom
sayantanmandal1:parsebytes-exact-integers

Conversation

@sayantanmandal1

Copy link
Copy Markdown

ParseBytes runs the number through float64 even for whole numbers, which causes
two things:

ParseBytes("9007199254740993B")     // 9007199254740992, should be ...993
ParseBytes("18446744073709551615")  // errors "too large", but that is MaxUint64

ParseBigBytes already uses big.Rat and stays exact, so the uint64 path losing
precision looks accidental.

When the number has no decimal point this parses it with strconv.ParseUint and
multiplies with bits.Mul64, keeping the existing "too large" error only for real
overflow. Fractional input like "1.5 MB" still uses the float path. Added a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant