From 0aa29682d0e079e4e92b6b9eb75413ab30522237 Mon Sep 17 00:00:00 2001 From: John Shin Date: Mon, 7 Aug 2023 00:09:14 -0700 Subject: [PATCH] seq: display -0 --- src/uu/seq/src/extendedbigint.rs | 12 ++---------- src/uu/seq/src/seq.rs | 9 +++------ 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/uu/seq/src/extendedbigint.rs b/src/uu/seq/src/extendedbigint.rs index bbe64300a..46153bb7d 100644 --- a/src/uu/seq/src/extendedbigint.rs +++ b/src/uu/seq/src/extendedbigint.rs @@ -65,11 +65,7 @@ impl Display for ExtendedBigInt { Self::BigInt(n) => n.fmt(f), Self::Infinity => f32::INFINITY.fmt(f), Self::MinusInfinity => f32::NEG_INFINITY.fmt(f), - Self::MinusZero => { - // FIXME Come up with a way of formatting this with a - // "-" prefix. - 0.fmt(f) - } + Self::MinusZero => "-0".fmt(f), Self::Nan => "nan".fmt(f), } } @@ -206,13 +202,9 @@ mod tests { #[test] fn test_display() { assert_eq!(format!("{}", ExtendedBigInt::BigInt(BigInt::zero())), "0"); + assert_eq!(format!("{}", ExtendedBigInt::MinusZero), "-0"); assert_eq!(format!("{}", ExtendedBigInt::Infinity), "inf"); assert_eq!(format!("{}", ExtendedBigInt::MinusInfinity), "-inf"); assert_eq!(format!("{}", ExtendedBigInt::Nan), "nan"); - // FIXME Come up with a way of displaying negative zero as - // "-0". Currently it displays as just "0". - // - // assert_eq!(format!("{}", ExtendedBigInt::MinusZero), "-0"); - // } } diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 2e55efa4a..de883fe8a 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -223,16 +223,13 @@ fn write_value_int( value: &ExtendedBigInt, width: usize, pad: bool, - is_first_iteration: bool, ) -> std::io::Result<()> { let value_as_str = if pad { - if *value == ExtendedBigInt::MinusZero && is_first_iteration { - format!("-{value:>0width$}", width = width - 1) + if *value == ExtendedBigInt::MinusZero { + format!("{value:00width$}") } - } else if *value == ExtendedBigInt::MinusZero && is_first_iteration { - format!("-{value}") } else { format!("{value}") }; @@ -347,7 +344,7 @@ fn print_seq_integers( exit(1); } } - None => write_value_int(&mut stdout, &value, padding, pad, is_first_iteration)?, + None => write_value_int(&mut stdout, &value, padding, pad)?, } // TODO Implement augmenting addition. value = value + increment.clone();