Commit 003f21a
fix(od):fix GNU coreutils test od float.sh (#9534)
* 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]>1 parent ee39b35 commit 003f21a
2 files changed
+88
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
40 | 88 | | |
41 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
42 | 95 | | |
43 | 96 | | |
44 | 97 | | |
| |||
82 | 135 | | |
83 | 136 | | |
84 | 137 | | |
85 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
86 | 142 | | |
87 | 143 | | |
88 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
200 | 226 | | |
201 | 227 | | |
202 | 228 | | |
| |||
210 | 236 | | |
211 | 237 | | |
212 | 238 | | |
213 | | - | |
| 239 | + | |
214 | 240 | | |
215 | 241 | | |
216 | 242 | | |
| |||
237 | 263 | | |
238 | 264 | | |
239 | 265 | | |
240 | | - | |
| 266 | + | |
241 | 267 | | |
242 | 268 | | |
243 | 269 | | |
| |||
264 | 290 | | |
265 | 291 | | |
266 | 292 | | |
267 | | - | |
| 293 | + | |
268 | 294 | | |
269 | 295 | | |
270 | 296 | | |
| |||
0 commit comments