Trait number_traits::Num [] [src]

pub trait Num: Clone + One + Zero + Bounded + NumConst + ToPrimitive + FromPrimitive + PartialEq + PartialOrd + ToString + Add<Self, Output = Self> + Mul<Self, Output = Self> + Sub<Self, Output = Self> + Div<Self, Output = Self> + Rem<Self, Output = Self> + AddAssign<Self> + MulAssign<Self> + SubAssign<Self> + DivAssign<Self> + RemAssign<Self> {
    fn min(&self, other: &Self) -> Self { ... }
fn max(&self, other: &Self) -> Self { ... }
fn clamp(&self, min: &Self, max: &Self) -> Self { ... }
fn clamp01(&self) -> Self { ... }
fn abs_diff(&self, other: &Self) -> Self { ... } }

Provided Methods

Examples

use number_traits::Num;

assert_eq!(Num::min(&50, &100), 50);
assert_eq!(Num::min(&100, &50), 50);

Examples

use number_traits::Num;

assert_eq!(Num::max(&50, &100), 100);
assert_eq!(Num::max(&100, &50), 100);

Examples

use number_traits::Num;

assert_eq!((-50).clamp(&0, &100), 0);
assert_eq!(50.clamp(&0, &100), 50);
assert_eq!(150.clamp(&0, &100), 100);

Examples

use number_traits::Num;

assert_eq!((-0.5).clamp01(), 0.0);
assert_eq!(0.5.clamp01(), 0.5);
assert_eq!(1.50.clamp01(), 1.0);

Examples

use number_traits::Num;

assert_eq!(10.abs_diff(&15), 5);
assert_eq!(15.abs_diff(&10), 5);

Implementors