-
Notifications
You must be signed in to change notification settings - Fork 36
Fix Int64.toRadixStringUnsigned extra leading digits
#926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Currently this adds an extra '0' when the result is single digit, e.g. '02' instead of '2'. To be able to use the standard library `toRadixString`, we split the number into two halves, then calculate the lowest digit and the rest of the digits separately. With the lowest digit removed, the rest of the digits can be passed as a positive integer to `toRadixString`. The resulting strings are then concatenated to get the final result. The problem occurs when the number can be printed as a single digit. In this case the rest of the number can be printed as '0', giving us e.g. '02' instead of '2'. To fix, we return early by calling the standard library `toRadixString` when the high 32 bits are zero. This works because - The problem is only when printing single digits (as the lowest digit and the rest are printed separately, and the problem is when the "rest" part is 0) - Single-digit numbers need to have high 32-bits as zero (otherwise they'll be negative and printed as many digits, or positive but larger than single digit). - When the high 32-bits are all zero, the number is positive, and can be converted to string with the standard library signed `toRadixString`.
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
PR HealthLicense Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
This check can be disabled by tagging the PR with API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
This check can be disabled by tagging the PR with
Breaking changes
|
| Package | Change | Current Version | New Version | Needed Version | Looking good? |
|---|---|---|---|---|---|
| fixnum | Breaking | 1.1.1 | 1.2.0-wip | 2.0.0 Got "1.2.0-wip" expected >= "2.0.0" (breaking changes) |
This check can be disabled by tagging the PR with skip-breaking-check.
Coverage ✔️
| File | Coverage |
|---|---|
| pkgs/fixnum/lib/src/int64_native.dart | 💚 96 % ⬆️ 0 % |
This check for test coverage is informational (issues shown here will not fail the PR).
This check can be disabled by tagging the PR with skip-coverage-check.
Currently
Int64.toRadixStringUnsignedadds an extra '0' when the result is single digit, e.g. '02' instead of '2'.To be able to use the standard library
toRadixString, we split the number into two halves, then calculate the lowest digit and the rest of the digits separately. With the lowest digit removed, the rest of the digits can be passed as a positive integer totoRadixString. The resulting strings are then concatenated to get the final result.The problem occurs when the number can be printed as a single digit. In this case the rest of the number is printed as '0', giving us e.g. '02' instead of '2'.
To fix, we return early by calling the standard library
toRadixStringwhen the number is positive.This works because
The problem is only when printing single digits (as the lowest digit and the rest are printed separately, and the problem is when the "rest" part is 0)
Single-digit numbers need to have high 32-bits as zero (otherwise they'll be negative and printed as many digits, or positive but larger than single digit).
When the high 32-bits are all zero, the number is positive, and can be converted to string directly with the standard library signed
toRadixString.