mirror of
https://github.com/uutils/coreutils
synced 2024-12-16 16:22:40 +00:00
seq: update inf and nan parsing
This commit is contained in:
parent
426cce7df0
commit
d345a280bf
1 changed files with 19 additions and 21 deletions
|
@ -69,27 +69,25 @@ fn parse_no_decimal_no_exponent(s: &str) -> Result<PreciseNumber, ParseNumberErr
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Possibly "NaN" or "inf".
|
// Possibly "NaN" or "inf".
|
||||||
//
|
if let Ok(num) = f32::from_str(s) {
|
||||||
// TODO In Rust v1.53.0, this change
|
// pattern matching on floating point literal is not encouraged 'https://github.com/rust-lang/rust/issues/41620'
|
||||||
// https://github.com/rust-lang/rust/pull/78618 improves the
|
if num == f32::INFINITY {
|
||||||
// parsing of floats to include being able to parse "NaN"
|
Ok(PreciseNumber::new(
|
||||||
// and "inf". So when the minimum version of this crate is
|
Number::Float(ExtendedBigDecimal::Infinity),
|
||||||
// increased to 1.53.0, we should just use the built-in
|
0,
|
||||||
// `f32` parsing instead.
|
0,
|
||||||
if s.eq_ignore_ascii_case("inf") {
|
))
|
||||||
Ok(PreciseNumber::new(
|
} else if num == f32::NEG_INFINITY {
|
||||||
Number::Float(ExtendedBigDecimal::Infinity),
|
Ok(PreciseNumber::new(
|
||||||
0,
|
Number::Float(ExtendedBigDecimal::MinusInfinity),
|
||||||
0,
|
0,
|
||||||
))
|
0,
|
||||||
} else if s.eq_ignore_ascii_case("-inf") {
|
))
|
||||||
Ok(PreciseNumber::new(
|
} else if num.is_nan() {
|
||||||
Number::Float(ExtendedBigDecimal::MinusInfinity),
|
Err(ParseNumberError::Nan)
|
||||||
0,
|
} else {
|
||||||
0,
|
Err(ParseNumberError::Float)
|
||||||
))
|
}
|
||||||
} else if s.eq_ignore_ascii_case("nan") || s.eq_ignore_ascii_case("-nan") {
|
|
||||||
Err(ParseNumberError::Nan)
|
|
||||||
} else {
|
} else {
|
||||||
Err(ParseNumberError::Float)
|
Err(ParseNumberError::Float)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue