Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down