diff --git a/src/float.rs b/src/float.rs index d0d21a5..d38dd1a 100644 --- a/src/float.rs +++ b/src/float.rs @@ -2297,6 +2297,38 @@ pub trait TotalOrder { /// check_lt(-0.0_f64, 0.0_f64); /// ``` fn total_cmp(&self, other: &Self) -> Ordering; + + /// Get the maximum of two numbers, propagating NaN + /// + /// For this operation, -0.0 is considered to be less than +0.0 as + /// specified in IEEE 754-2019. + #[must_use] + fn maximum(self, other: Self) -> Self + where + Self: FloatCore, + { + match (self.is_nan(), other.is_nan()) { + (true, _) => self, + (_, true) => other, + _ => core::cmp::max_by(self, other, Self::total_cmp), + } + } + + /// Get the minimum of two numbers, propagating NaN + /// + /// For this operation, -0.0 is considered to be less than +0.0 as + /// specified in IEEE 754-2019. + #[must_use] + fn minimum(self, other: Self) -> Self + where + Self: FloatCore, + { + match (self.is_nan(), other.is_nan()) { + (true, _) => self, + (_, true) => other, + _ => core::cmp::min_by(self, other, Self::total_cmp), + } + } } macro_rules! totalorder_impl { ($T:ident, $I:ident, $U:ident, $bits:expr) => {