Add .min and .max.

This commit is contained in:
sebcrozet 2018-12-22 18:03:32 +01:00
parent b4b66bddd2
commit cae2be5cad
2 changed files with 41 additions and 3 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "nalgebra"
version = "0.16.5"
version = "0.16.12"
authors = [ "Sébastien Crozet <developer@crozet.re>" ]
description = "Linear algebra library with transformations and statically-sized or dynamically-sized matrices."

View File

@ -761,7 +761,7 @@ where
}
impl<N: Scalar + PartialOrd + Signed, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
/// Returns the absolute value of the coefficient with the largest absolute value.
/// Returns the absolute value of the component with the largest absolute value.
#[inline]
pub fn amax(&self) -> N {
let mut max = N::zero();
@ -777,7 +777,7 @@ impl<N: Scalar + PartialOrd + Signed, R: Dim, C: Dim, S: Storage<N, R, C>> Matri
max
}
/// Returns the absolute value of the coefficient with the smallest absolute value.
/// Returns the absolute value of the component with the smallest absolute value.
#[inline]
pub fn amin(&self) -> N {
let mut it = self.iter();
@ -796,4 +796,42 @@ impl<N: Scalar + PartialOrd + Signed, R: Dim, C: Dim, S: Storage<N, R, C>> Matri
min
}
/// Returns the component with the largest value.
#[inline]
pub fn max(&self) -> N {
let mut it = self.iter();
let mut max = it
.next()
.expect("max: empty matrices not supported.");
for e in it {
let ae = e;
if ae > max {
max = ae;
}
}
*max
}
/// Returns the component with the smallest value.
#[inline]
pub fn min(&self) -> N {
let mut it = self.iter();
let mut min = it
.next()
.expect("min: empty matrices not supported.");
for e in it {
let ae = e;
if ae < min {
min = ae;
}
}
*min
}
}