-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(od):fix GNU coreutils test od float.sh #9534
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
Merged
Merged
+88
−6
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
Implement trim_float_repr() to remove trailing zeros from float strings while preserving signs and exponents, and pad_float_repr() to align trimmed floats to fixed width. Update format_item_f16() and format_item_bf16() to produce compact output matching GNU od. Add regression tests for float16 and bfloat16 compact printing.
…ility Reformat the format! macro call in the format_item_bf16 function in prn_float.rs to span multiple lines, improving code readability without changing functionality.
Remove trimming of trailing zeros from f16 and bf16 float representations in od output to maintain original precision and align behavior with f32/f64 formatters, ensuring stable output across platforms. Update corresponding tests to reflect the change in expected output.
- Remove redundant `width = width` parameter from `format!` macro in `pad_float_repr` - Add "bfloat" to spell-checker ignore list for better test coverage on bf16 format
Add `trim_trailing_zeros` function to remove trailing zeros and redundant decimal points from formatted floats, ensuring compact output matching GNU od for f16 and bf16 types. Update `format_item_f16` and `format_item_bf16` to apply trimming before padding.
…NU od output Remove the `trim_trailing_zeros` function and update `format_item_f16` and `format_item_bf16` to keep the raw formatted strings without trimming trailing zeros. This ensures consistent column widths and aligns with GNU od behavior for 16-bit float representations, preventing misalignment in output tables.
… format_item_f16 The format! macro call in format_item_f16 was split across multiple lines with newlines. This change consolidates it into a single line for improved code readability and consistency with similar patterns in the file, without altering the function's output or logic.
|
GNU testsuite comparison: |
…tputs - Add `trim_float_repr` function to remove unnecessary trailing zeros and padding from normalized float strings, leaving exponents unchanged. - Update `format_item_f16` and `format_item_bf16` to apply trimming while maintaining column alignment via re-padding. - Update test expectations to reflect the more compact float representations (e.g., "1" instead of "1.0000000").
Replace `if let Some(_) = s.find('.')` with `s.find('.').is_some()` in the `trim_float_repr` function to improve code clarity and idiomatic Rust usage while maintaining the same logic for checking decimal presence=black.
|
GNU testsuite comparison: |
1 similar comment
|
GNU testsuite comparison: |
cakebaker
reviewed
Dec 1, 2025
Co-authored-by: Daniel Hofstetter <[email protected]>
|
GNU testsuite comparison: |
Contributor
Great, thanks! |
romanstingler
pushed a commit
to romanstingler/coreutils
that referenced
this pull request
Dec 14, 2025
* feat: add compact float formatting for half and bfloat16 in od
Implement trim_float_repr() to remove trailing zeros from float strings while preserving signs and exponents, and pad_float_repr() to align trimmed floats to fixed width. Update format_item_f16() and format_item_bf16() to produce compact output matching GNU od. Add regression tests for float16 and bfloat16 compact printing.
* refactor(od): format multiline format! in format_item_bf16 for readability
Reformat the format! macro call in the format_item_bf16 function in prn_float.rs
to span multiple lines, improving code readability without changing functionality.
* fix(od): preserve canonical precision for f16/bf16 float formats
Remove trimming of trailing zeros from f16 and bf16 float representations
in od output to maintain original precision and align behavior with
f32/f64 formatters, ensuring stable output across platforms. Update
corresponding tests to reflect the change in expected output.
* refactor(od): simplify float padding format and update tests
- Remove redundant `width = width` parameter from `format!` macro in `pad_float_repr`
- Add "bfloat" to spell-checker ignore list for better test coverage on bf16 format
* feat(od): trim trailing zeros in float outputs for GNU compatibility
Add `trim_trailing_zeros` function to remove trailing zeros and redundant decimal points from formatted floats, ensuring compact output matching GNU od for f16 and bf16 types. Update `format_item_f16` and `format_item_bf16` to apply trimming before padding.
* fix: preserve trailing zeros in F16 and BF16 float formats to match GNU od output
Remove the `trim_trailing_zeros` function and update `format_item_f16` and `format_item_bf16` to keep the raw formatted strings without trimming trailing zeros. This ensures consistent column widths and aligns with GNU od behavior for 16-bit float representations, preventing misalignment in output tables.
* refactor(od/prn_float): combine multiline format! into single line in format_item_f16
The format! macro call in format_item_f16 was split across multiple lines with newlines. This change consolidates it into a single line for improved code readability and consistency with similar patterns in the file, without altering the function's output or logic.
* feat(od): trim trailing zeros in half-precision and bfloat16 float outputs
- Add `trim_float_repr` function to remove unnecessary trailing zeros and padding from normalized float strings, leaving exponents unchanged.
- Update `format_item_f16` and `format_item_bf16` to apply trimming while maintaining column alignment via re-padding.
- Update test expectations to reflect the more compact float representations (e.g., "1" instead of "1.0000000").
* refactor: simplify float trimming condition in prn_float.rs
Replace `if let Some(_) = s.find('.')` with `s.find('.').is_some()` in the `trim_float_repr` function to improve code clarity and idiomatic Rust usage while maintaining the same logic for checking decimal presence=black.
* Update src/uu/od/src/prn_float.rs
Co-authored-by: Daniel Hofstetter <[email protected]>
---------
Co-authored-by: Daniel Hofstetter <[email protected]>
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.
Creating and modifying test cases to ensure od-float.sh passes tests
related
#9127