Skip to content

Commit 67ffc0e

Browse files
committed
od: default -t f to double precision
1 parent ef8e45c commit 67ffc0e

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

src/uu/od/src/parse_formats.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ fn od_format_type(type_char: FormatType, byte_size: u8) -> Option<FormatterItemI
8686
(FormatType::HexadecimalInt, 8) => Some(FORMAT_ITEM_HEX64),
8787

8888
(FormatType::Float, 2) => Some(FORMAT_ITEM_F16),
89-
(FormatType::Float, 0 | 4) => Some(FORMAT_ITEM_F32),
89+
(FormatType::Float, 4) => Some(FORMAT_ITEM_F32),
90+
(FormatType::Float, 0) => Some(FORMAT_ITEM_F64),
9091
(FormatType::Float, 8) => Some(FORMAT_ITEM_F64),
9192
(FormatType::Float, 16) => Some(FORMAT_ITEM_LONG_DOUBLE),
9293

@@ -521,7 +522,7 @@ fn test_long_format_x_default() {
521522
fn test_long_format_f_default() {
522523
assert_eq!(
523524
parse_format_flags_str(&["od", "--format=f"]).unwrap(),
524-
vec![FORMAT_ITEM_F32]
525+
vec![FORMAT_ITEM_F64]
525526
);
526527
}
527528

@@ -587,7 +588,7 @@ fn test_mixed_formats() {
587588
ParsedFormatterItemInfo::new(FORMAT_ITEM_HEX8, false), // tx1
588589
ParsedFormatterItemInfo::new(FORMAT_ITEM_DEC16U, false), // tu2
589590
ParsedFormatterItemInfo::new(FORMAT_ITEM_C, false), // tc
590-
ParsedFormatterItemInfo::new(FORMAT_ITEM_F32, false), // tf
591+
ParsedFormatterItemInfo::new(FORMAT_ITEM_F64, false), // tf
591592
ParsedFormatterItemInfo::new(FORMAT_ITEM_HEX16, false), // x
592593
]
593594
);

tests/by-util/test_od.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,52 @@ fn test_bfloat16_compact() {
223223
.stdout_only(" 1 1\n");
224224
}
225225

226+
#[test]
227+
fn test_tf_default_is_double() {
228+
let input: [u8; 8] = [0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x40];
229+
let default_output = new_ucmd!()
230+
.arg("--endian=little")
231+
.arg("-An")
232+
.arg("-tf")
233+
.run_piped_stdin(&input[..])
234+
.success()
235+
.stdout_str()
236+
.to_string();
237+
238+
let explicit_double_output = new_ucmd!()
239+
.arg("--endian=little")
240+
.arg("-An")
241+
.arg("-tfD")
242+
.run_piped_stdin(&input[..])
243+
.success()
244+
.stdout_str()
245+
.to_string();
246+
247+
let explicit_float_output = new_ucmd!()
248+
.arg("--endian=little")
249+
.arg("-An")
250+
.arg("-tfF")
251+
.run_piped_stdin(&input[..])
252+
.success()
253+
.stdout_str()
254+
.to_string();
255+
256+
assert_eq!(default_output, explicit_double_output);
257+
assert_ne!(default_output, explicit_float_output);
258+
}
259+
260+
#[test]
261+
fn test_tf_explicit_float_still_uses_4_bytes() {
262+
let input: [u8; 8] = [0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x40];
263+
new_ucmd!()
264+
.arg("--endian=little")
265+
.arg("-An")
266+
.arg("-tfF")
267+
.run_piped_stdin(&input[..])
268+
.success()
269+
.stdout_only(" 1.0000000 2.0000000\n");
270+
}
271+
226272
#[test]
227273
fn test_f16() {
228274
let input: [u8; 14] = [

0 commit comments

Comments
 (0)