mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Fix comparison of empty string to numeric f64 sort
This commit is contained in:
parent
94cd6540ba
commit
b09ccaf6b1
1 changed files with 9 additions and 5 deletions
|
@ -383,12 +383,16 @@ fn permissive_f64_parse(a: &str) -> f64 {
|
||||||
// because there's no way to handle both CSV and thousands separators without a new flag.
|
// because there's no way to handle both CSV and thousands separators without a new flag.
|
||||||
// GNU sort treats "1,234" as "1" in numeric, so maybe it's fine.
|
// GNU sort treats "1,234" as "1" in numeric, so maybe it's fine.
|
||||||
// GNU sort treats "NaN" as non-number in numeric, so it needs special care.
|
// GNU sort treats "NaN" as non-number in numeric, so it needs special care.
|
||||||
let sa: &str = a.split_whitespace().next().unwrap();
|
match a.split_whitespace().next() {
|
||||||
|
None => std::f64::NEG_INFINITY,
|
||||||
|
Some(sa) => {
|
||||||
match sa.parse::<f64>() {
|
match sa.parse::<f64>() {
|
||||||
Ok(a) if a.is_nan() => std::f64::NEG_INFINITY,
|
Ok(a) if a.is_nan() => std::f64::NEG_INFINITY,
|
||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
Err(_) => std::f64::NEG_INFINITY,
|
Err(_) => std::f64::NEG_INFINITY,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compares two floating point numbers, with errors being assumed to be -inf.
|
/// Compares two floating point numbers, with errors being assumed to be -inf.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue