Skip to content

Commit

Permalink
Make Debug impls delegate directly to inner float
Browse files Browse the repository at this point in the history
Resolves #152
  • Loading branch information
Ten0 committed Jul 29, 2024
1 parent d76512a commit 6fae20e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn canonicalize_signed_zero<T: FloatCore>(x: T) -> T {
/// s.insert(OrderedFloat(NAN));
/// assert!(s.contains(&OrderedFloat(NAN)));
/// ```
#[derive(Debug, Default, Clone, Copy)]
#[derive(Default, Clone, Copy)]
#[repr(transparent)]
pub struct OrderedFloat<T>(pub T);

Expand Down Expand Up @@ -193,6 +193,13 @@ impl<T: FloatCore> Hash for OrderedFloat<T> {
}
}

impl<T: fmt::Debug> fmt::Debug for OrderedFloat<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}

impl<T: FloatCore + fmt::Display> fmt::Display for OrderedFloat<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -1090,7 +1097,7 @@ impl<T: FloatCore + Num> Num for OrderedFloat<T> {
/// // This will panic:
/// let c = a + b;
/// ```
#[derive(PartialOrd, PartialEq, Debug, Default, Clone, Copy)]
#[derive(PartialOrd, PartialEq, Default, Clone, Copy)]
#[repr(transparent)]
pub struct NotNan<T>(T);

Expand Down Expand Up @@ -1177,6 +1184,13 @@ impl<T: FloatCore> Hash for NotNan<T> {
}
}

impl<T: fmt::Debug> fmt::Debug for NotNan<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}

impl<T: FloatCore + fmt::Display> fmt::Display for NotNan<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down

0 comments on commit 6fae20e

Please sign in to comment.