-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
printf: Integers: When value and precision are zero, nothing is printed. #7513
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
Closed
Conversation
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
Will make it possible to directly print ExtendedBigDecimal in `seq`, and gradually get rid of limited f64 precision in other tools (e.g. `printf`). Changes are mostly mechanical, we reexport ExtendedBigDecimal directly in format to keep the imports slightly shorter.
Using an associated type in Formatter trait was quite nice, but, in a follow-up change, we'd like to pass a _reference_ to the Float Formatter, while just passing i64/u64 as a value to the Int formatters. Associated type doesn't allow for that, so we turn it into a generic instead. This makes Format<> a bit more complicated though, as we need to specify both the Formatter, _and_ the type to be formatted.
Some test cases require to handle "negative" NaN. Handle it similarly to "positive" NaN.
Allows easier conversion.
Only changes the external interface, right now the number is casted back to f64 for printing. We'll update that in follow-up.
First modify Format.fmt to extract absolute value and sign, then modify printing on non-finite values (inf or nan).
Also add a few unit tests to make sure precision is not lost anymore.
No more f64 operations needed, we just trim (or extend) BigDecimal to appropriate precision, get the digits as a string, then add the decimal point. Similar to what BigDecimal::write_scientific_notation does, but we need a little bit more control.
Similar logic to scientific printing. Also add a few more tests around corner cases where we switch from decimal to scientific printing.
Display hexadecimal floats with arbitrary precision. Note that some of the logic will produce extremely large BitInt as intermediate values: there is some optimization possible here, but the current implementation appears to work fine for reasonable numbers (e.g. whatever would previously fit in a f64, and even with somewhat large precision).
`printf "%05.2f" inf` should print ` inf`, not `00inf`. Add a test to cover that case, too.
Now that uucore format functions take in an ExtendedBigDecimal, we can use those in all cases.
In most common use cases: - We can bypass a lot of `write_output` when width == 0. - Simplify format_float_decimal when the input is an integer. Also document another interesting case in src/uu/seq/BENCHMARKING.md.
- Formatter<u64> and Formatter<i64> now return early if precision and value are 0
Author
|
Should've read contrib.md first |
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.
Changes made for this PR are based on PR #7458 due to its extensive changes in the formatting code.
Fixes Issue #7509
Old behavior:
New behavior: