diff -r 3868555d135c -r 32f5062ee477 src/nanleast.rs --- a/src/nanleast.rs Fri May 15 14:46:30 2026 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/*! -This module provides an artificial total order of floating point numbers. - -The [`NaNLeast`]`` container for `F` a [`Float`] puts `F` in an [`Ord`] total order with -`NaN` the least element. This allows the numbers to be sorted with `NaN` the “least important” -element when looking for the maximum. Thus erroneous computations producing `NaN` can be ignored -when there are good results. -*/ - -use crate::types::Float; -use std::cmp::{PartialOrd,Ord,Ordering,Ordering::*}; - -/// A container for floating point numbers. -/// -/// The implementation of [`Ord`] for this type type sorts `NaN` as the least element. -#[derive(Debug, Clone, Copy)] -pub struct NaNLeast(pub F); - -impl Ord for NaNLeast { - #[inline] - fn cmp(&self, NaNLeast(b) : &Self) -> Ordering { - let NaNLeast(a) = self; - match a.partial_cmp(b) { - None => match (a.is_nan(), b.is_nan()) { - (true, false) => Less, - (false, true) => Greater, - _ => Equal // The case (true, true) should not occur! - } - Some(order) => order - } - } -} - -impl PartialEq for NaNLeast { - #[inline] - fn eq(&self, other : &Self) -> bool { self.cmp(other)==Equal } -} - -impl Eq for NaNLeast { } - -impl PartialOrd for NaNLeast { - #[inline] - fn partial_cmp(&self, other : &Self) -> Option { Some(self.cmp(other)) } -}