mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
seq: Eliminated special handling of -0.0
This commit is contained in:
parent
13dbb2ce12
commit
aacff13ec3
2 changed files with 19 additions and 43 deletions
|
@ -130,14 +130,7 @@ impl Display for ExtendedBigDecimal {
|
||||||
}
|
}
|
||||||
ExtendedBigDecimal::Infinity => f32::INFINITY.fmt(f),
|
ExtendedBigDecimal::Infinity => f32::INFINITY.fmt(f),
|
||||||
ExtendedBigDecimal::MinusInfinity => f32::NEG_INFINITY.fmt(f),
|
ExtendedBigDecimal::MinusInfinity => f32::NEG_INFINITY.fmt(f),
|
||||||
ExtendedBigDecimal::MinusZero => {
|
ExtendedBigDecimal::MinusZero => (-0.0f32).fmt(f),
|
||||||
// FIXME In Rust version 1.53.0 and later, the display
|
|
||||||
// of floats was updated to allow displaying negative
|
|
||||||
// zero. See
|
|
||||||
// https://github.com/rust-lang/rust/pull/78618. Currently,
|
|
||||||
// this just formats "0.0".
|
|
||||||
(0.0f32).fmt(f)
|
|
||||||
}
|
|
||||||
ExtendedBigDecimal::Nan => "nan".fmt(f),
|
ExtendedBigDecimal::Nan => "nan".fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,11 +273,6 @@ mod tests {
|
||||||
assert_eq!(format!("{}", ExtendedBigDecimal::Infinity), "inf");
|
assert_eq!(format!("{}", ExtendedBigDecimal::Infinity), "inf");
|
||||||
assert_eq!(format!("{}", ExtendedBigDecimal::MinusInfinity), "-inf");
|
assert_eq!(format!("{}", ExtendedBigDecimal::MinusInfinity), "-inf");
|
||||||
assert_eq!(format!("{}", ExtendedBigDecimal::Nan), "nan");
|
assert_eq!(format!("{}", ExtendedBigDecimal::Nan), "nan");
|
||||||
// FIXME In Rust version 1.53.0 and later, the display of floats
|
assert_eq!(format!("{}", ExtendedBigDecimal::MinusZero), "-0");
|
||||||
// was updated to allow displaying negative zero. Until then, we
|
|
||||||
// just display `MinusZero` as "0.0".
|
|
||||||
//
|
|
||||||
// assert_eq!(format!("{}", ExtendedBigDecimal::MinusZero), "-0.0");
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,27 +198,15 @@ fn done_printing<T: Zero + PartialOrd>(next: &T, increment: &T, last: &T) -> boo
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write a big decimal formatted according to the given parameters.
|
/// Write a big decimal formatted according to the given parameters.
|
||||||
///
|
|
||||||
/// This method is an adapter to support displaying negative zero on
|
|
||||||
/// Rust versions earlier than 1.53.0. After that version, we should be
|
|
||||||
/// able to display negative zero using the default formatting provided
|
|
||||||
/// by `-0.0f32`, for example.
|
|
||||||
fn write_value_float(
|
fn write_value_float(
|
||||||
writer: &mut impl Write,
|
writer: &mut impl Write,
|
||||||
value: &ExtendedBigDecimal,
|
value: &ExtendedBigDecimal,
|
||||||
width: usize,
|
width: usize,
|
||||||
precision: usize,
|
precision: usize,
|
||||||
is_first_iteration: bool,
|
_is_first_iteration: bool,
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
let value_as_str = if *value == ExtendedBigDecimal::MinusZero && is_first_iteration {
|
let value_as_str =
|
||||||
format!(
|
if *value == ExtendedBigDecimal::Infinity || *value == ExtendedBigDecimal::MinusInfinity {
|
||||||
"-{value:>0width$.precision$}",
|
|
||||||
value = value,
|
|
||||||
width = if width > 0 { width - 1 } else { width },
|
|
||||||
precision = precision,
|
|
||||||
)
|
|
||||||
} else if *value == ExtendedBigDecimal::Infinity || *value == ExtendedBigDecimal::MinusInfinity
|
|
||||||
{
|
|
||||||
format!(
|
format!(
|
||||||
"{value:>width$.precision$}",
|
"{value:>width$.precision$}",
|
||||||
value = value,
|
value = value,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue