mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
seq: simplyfy nan and inf parsing
This commit is contained in:
parent
2bb56d44a4
commit
9c0b9cae56
1 changed files with 7 additions and 22 deletions
|
@ -69,28 +69,13 @@ 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) {
|
let float_val = match s.to_ascii_lowercase().as_str() {
|
||||||
// pattern matching on floating point literal is not encouraged 'https://github.com/rust-lang/rust/issues/41620'
|
"inf" | "infinity" => ExtendedBigDecimal::Infinity,
|
||||||
if num == f32::INFINITY {
|
"-inf" | "-infinity" => ExtendedBigDecimal::MinusInfinity,
|
||||||
Ok(PreciseNumber::new(
|
"nan" | "-nan" => return Err(ParseNumberError::Nan),
|
||||||
Number::Float(ExtendedBigDecimal::Infinity),
|
_ => return Err(ParseNumberError::Float),
|
||||||
0,
|
};
|
||||||
0,
|
Ok(PreciseNumber::new(Number::Float(float_val), 0, 0))
|
||||||
))
|
|
||||||
} else if num == f32::NEG_INFINITY {
|
|
||||||
Ok(PreciseNumber::new(
|
|
||||||
Number::Float(ExtendedBigDecimal::MinusInfinity),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
))
|
|
||||||
} else if num.is_nan() {
|
|
||||||
Err(ParseNumberError::Nan)
|
|
||||||
} else {
|
|
||||||
Err(ParseNumberError::Float)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Err(ParseNumberError::Float)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue