1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #1296 from rkuslak/master

Fix comparison of empty string to numeric f64 sort
This commit is contained in:
cnd 2018-09-30 18:51:07 +04:00 committed by GitHub
commit a161b7e803
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -383,13 +383,17 @@ fn permissive_f64_parse(a: &str) -> f64 {
// 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 "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>() {
Ok(a) if a.is_nan() => std::f64::NEG_INFINITY,
Ok(a) => a,
Err(_) => std::f64::NEG_INFINITY,
}
}
}
}
/// Compares two floating point numbers, with errors being assumed to be -inf.
/// Stops coercing at the first whitespace char, so 1e2 will parse as 100 but