diff --git a/src/uu/od/src/parse_formats.rs b/src/uu/od/src/parse_formats.rs index 1103b77cac3..e3312b87603 100644 --- a/src/uu/od/src/parse_formats.rs +++ b/src/uu/od/src/parse_formats.rs @@ -86,7 +86,8 @@ fn od_format_type(type_char: FormatType, byte_size: u8) -> Option Some(FORMAT_ITEM_HEX64), (FormatType::Float, 2) => Some(FORMAT_ITEM_F16), - (FormatType::Float, 0 | 4) => Some(FORMAT_ITEM_F32), + (FormatType::Float, 4) => Some(FORMAT_ITEM_F32), + (FormatType::Float, 0) => Some(FORMAT_ITEM_F64), (FormatType::Float, 8) => Some(FORMAT_ITEM_F64), (FormatType::Float, 16) => Some(FORMAT_ITEM_LONG_DOUBLE), @@ -521,7 +522,7 @@ fn test_long_format_x_default() { fn test_long_format_f_default() { assert_eq!( parse_format_flags_str(&["od", "--format=f"]).unwrap(), - vec![FORMAT_ITEM_F32] + vec![FORMAT_ITEM_F64] ); } @@ -587,7 +588,7 @@ fn test_mixed_formats() { ParsedFormatterItemInfo::new(FORMAT_ITEM_HEX8, false), // tx1 ParsedFormatterItemInfo::new(FORMAT_ITEM_DEC16U, false), // tu2 ParsedFormatterItemInfo::new(FORMAT_ITEM_C, false), // tc - ParsedFormatterItemInfo::new(FORMAT_ITEM_F32, false), // tf + ParsedFormatterItemInfo::new(FORMAT_ITEM_F64, false), // tf ParsedFormatterItemInfo::new(FORMAT_ITEM_HEX16, false), // x ] ); diff --git a/tests/by-util/test_od.rs b/tests/by-util/test_od.rs index 21cef8404ea..823f2d1dc51 100644 --- a/tests/by-util/test_od.rs +++ b/tests/by-util/test_od.rs @@ -223,6 +223,52 @@ fn test_bfloat16_compact() { .stdout_only(" 1 1\n"); } +#[test] +fn test_tf_default_is_double() { + let input: [u8; 8] = [0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x40]; + let default_output = new_ucmd!() + .arg("--endian=little") + .arg("-An") + .arg("-tf") + .run_piped_stdin(&input[..]) + .success() + .stdout_str() + .to_string(); + + let explicit_double_output = new_ucmd!() + .arg("--endian=little") + .arg("-An") + .arg("-tfD") + .run_piped_stdin(&input[..]) + .success() + .stdout_str() + .to_string(); + + let explicit_float_output = new_ucmd!() + .arg("--endian=little") + .arg("-An") + .arg("-tfF") + .run_piped_stdin(&input[..]) + .success() + .stdout_str() + .to_string(); + + assert_eq!(default_output, explicit_double_output); + assert_ne!(default_output, explicit_float_output); +} + +#[test] +fn test_tf_explicit_float_still_uses_4_bytes() { + let input: [u8; 8] = [0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x40]; + new_ucmd!() + .arg("--endian=little") + .arg("-An") + .arg("-tfF") + .run_piped_stdin(&input[..]) + .success() + .stdout_only(" 1.0000000 2.0000000\n"); +} + #[test] fn test_f16() { let input: [u8; 14] = [