Skip to content
Closed
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
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::fmt;
use std::io;
use std::mem;
use unreachable::unreachable;
use num_traits::Float;
use num_traits::{Float, Zero};

// masks for the parts of the IEEE 754 float
const SIGN_MASK: u64 = 0x8000000000000000u64;
Expand Down Expand Up @@ -516,6 +516,16 @@ impl<T: Float> Neg for NotNaN<T> {
}
}

impl<T: Float + Zero> Zero for NotNaN<T> {
fn zero() -> Self {
NotNaN(T::zero())
}

fn is_zero(&self) -> bool {
*self == Self::zero()
}
}

/// An error indicating an attempt to construct NotNaN from a NaN
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct FloatIsNaN;
Expand Down