Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Eq, Ord impls on FiniteF64 #187

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions src/primitive.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Implementation of the FiniteF64 primitive

use core::cmp::Ordering;

use crate::{TemporalError, TemporalResult};
use num_traits::{AsPrimitive, FromPrimitive, PrimInt};

Expand Down Expand Up @@ -215,6 +217,20 @@ impl PartialOrd<f64> for FiniteF64 {
}
}

impl Eq for FiniteF64 {}

impl Ord for FiniteF64 {
fn cmp(&self, other: &Self) -> Ordering {
match self.0.partial_cmp(&other.0) {
Some(ordering) => ordering,
None => {
debug_assert!(false, "could not compare finite f64: {self} {other}");
Ordering::Equal
}
}
}
}

#[cfg(test)]
mod tests {
use super::FiniteF64;
Expand Down
Loading