1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::f64;
#[cfg(feature = "nalgebra")]
mod projection;
mod stats;
mod vector;
pub use crate::stats::*;
#[cfg(feature = "nalgebra")]
pub use projection::*;
pub use crate::vector::*;
#[cfg(feature = "nalgebra")]
pub use nalgebra;
pub trait FloatIterExt {
fn float_min(&mut self) -> f64;
fn float_max(&mut self) -> f64;
}
impl<T> FloatIterExt for T
where
T: Iterator<Item = f64>,
{
fn float_max(&mut self) -> f64 {
self.fold(f64::NAN, f64::max)
}
fn float_min(&mut self) -> f64 {
self.fold(f64::NAN, f64::min)
}
}
#[test]
fn test_float_iter_min_max() {
let x = vec![1.0f64, 2.0, 0.0, -9.0, 0.0 / 0.0];
assert_eq!(x.iter().cloned().float_max(), 2.0);
assert_eq!(x.iter().cloned().float_min(), -9.0);
}