mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
commit
2b69803450
2 changed files with 5 additions and 16 deletions
|
@ -65,11 +65,7 @@ impl Display for ExtendedBigInt {
|
||||||
Self::BigInt(n) => n.fmt(f),
|
Self::BigInt(n) => n.fmt(f),
|
||||||
Self::Infinity => f32::INFINITY.fmt(f),
|
Self::Infinity => f32::INFINITY.fmt(f),
|
||||||
Self::MinusInfinity => f32::NEG_INFINITY.fmt(f),
|
Self::MinusInfinity => f32::NEG_INFINITY.fmt(f),
|
||||||
Self::MinusZero => {
|
Self::MinusZero => "-0".fmt(f),
|
||||||
// FIXME Come up with a way of formatting this with a
|
|
||||||
// "-" prefix.
|
|
||||||
0.fmt(f)
|
|
||||||
}
|
|
||||||
Self::Nan => "nan".fmt(f),
|
Self::Nan => "nan".fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,13 +202,9 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_display() {
|
fn test_display() {
|
||||||
assert_eq!(format!("{}", ExtendedBigInt::BigInt(BigInt::zero())), "0");
|
assert_eq!(format!("{}", ExtendedBigInt::BigInt(BigInt::zero())), "0");
|
||||||
|
assert_eq!(format!("{}", ExtendedBigInt::MinusZero), "-0");
|
||||||
assert_eq!(format!("{}", ExtendedBigInt::Infinity), "inf");
|
assert_eq!(format!("{}", ExtendedBigInt::Infinity), "inf");
|
||||||
assert_eq!(format!("{}", ExtendedBigInt::MinusInfinity), "-inf");
|
assert_eq!(format!("{}", ExtendedBigInt::MinusInfinity), "-inf");
|
||||||
assert_eq!(format!("{}", ExtendedBigInt::Nan), "nan");
|
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");
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,16 +223,13 @@ fn write_value_int(
|
||||||
value: &ExtendedBigInt,
|
value: &ExtendedBigInt,
|
||||||
width: usize,
|
width: usize,
|
||||||
pad: bool,
|
pad: bool,
|
||||||
is_first_iteration: bool,
|
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
let value_as_str = if pad {
|
let value_as_str = if pad {
|
||||||
if *value == ExtendedBigInt::MinusZero && is_first_iteration {
|
if *value == ExtendedBigInt::MinusZero {
|
||||||
format!("-{value:>0width$}", width = width - 1)
|
format!("{value:0<width$}")
|
||||||
} else {
|
} else {
|
||||||
format!("{value:>0width$}")
|
format!("{value:>0width$}")
|
||||||
}
|
}
|
||||||
} else if *value == ExtendedBigInt::MinusZero && is_first_iteration {
|
|
||||||
format!("-{value}")
|
|
||||||
} else {
|
} else {
|
||||||
format!("{value}")
|
format!("{value}")
|
||||||
};
|
};
|
||||||
|
@ -347,7 +344,7 @@ fn print_seq_integers(
|
||||||
exit(1);
|
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.
|
// TODO Implement augmenting addition.
|
||||||
value = value + increment.clone();
|
value = value + increment.clone();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue