Skip to content

Commit

Permalink
try to implement Saturating. No tests yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
radix committed Dec 23, 2017
1 parent f809cee commit 4b1be3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,20 @@ macro_rules! system {
}
}

impl<D, U, V> $crate::num::Saturating for Quantity<D, U, V>
where
D: Dimension + ?Sized,
U: Units<V> + ?Sized,
V: $crate::num::Saturating + $crate::num::Num + $crate::Conversion<V>,
{
fn saturating_add(self, v: Self) -> Self {
Quantity {value: self.value.saturating_add(v.value), ..self}
}
fn saturating_sub(self, v: Self) -> Self {
Quantity {value: self.value.saturating_sub(v.value), ..self}
}
}

impl<D, U, V> $crate::num::Zero for Quantity<D, U, V>
where
D: Dimension + ?Sized,
Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use self::mass::kilogram;
#[allow(unused_imports)]
use {Conversion, ConversionFactor};
#[allow(unused_imports)]
use num::{Float, FromPrimitive, One, Signed, Zero};
use num::{Float, FromPrimitive, One, Saturating, Signed, Zero};
use quickcheck::TestResult;
use lib::fmt::Debug;
use lib::marker::PhantomData;
Expand Down

0 comments on commit 4b1be3e

Please sign in to comment.