Add min and max, closes #3

This commit is contained in:
sharkdp committed 2018-01-14 21:43:29 +01:00
1 parent 05e5899643
commit 0047938349
3 files changed
+41 -13

No files matched your search

+16
View File
@@ -66,3 +66,19 @@ impl fmt::Display for Warnings {
}
}
}
/// A max function for f64's without NaNs
pub fn max(vals: &[f64]) -> f64 {
vals.iter()
.max_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap()
.clone()
}
/// A min function for f64's without NaNs
pub fn min(vals: &[f64]) -> f64 {
vals.iter()
.min_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap()
.clone()
}