pub struct NonNegF32(/* private fields */);Expand description
Wrapper around FiniteF32 that additionally guarantees a number that is
not negative, so 0.0 or higher.
Like FiniteF32, it compares and calculates with f32 directly.
Operations that can leave the range, such as a subtraction or a negation,
return a FiniteF32.
use spectrum_analyzer::NonNegF32;
let value = NonNegF32::from(0.5);
assert_eq!(value, 0.5);
assert!(value > 0.25);
assert_eq!(NonNegF32::from(0.25) - value, -0.25);§Panics
Creating a value from a number that is negative or not finite panics, and
so does an operation whose result leaves the range.
Self::try_new checks instead.
Implementations§
Trait Implementations§
impl Copy for NonNegF32
impl Eq for NonNegF32
Source§impl Ord for NonNegF32
impl Ord for NonNegF32
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for NonNegF32
impl PartialOrd for NonNegF32
Source§impl PartialOrd<NonNegF32> for f32
impl PartialOrd<NonNegF32> for f32
Source§impl PartialOrd<f32> for NonNegF32
impl PartialOrd<f32> for NonNegF32
Auto Trait Implementations§
impl Freeze for NonNegF32
impl RefUnwindSafe for NonNegF32
impl Send for NonNegF32
impl Sync for NonNegF32
impl Unpin for NonNegF32
impl UnsafeUnpin for NonNegF32
impl UnwindSafe for NonNegF32
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more