Skip to content

Commit

Permalink
Implement MulDivAssign with Ratio on RHS
Browse files Browse the repository at this point in the history
  • Loading branch information
jacg committed Aug 30, 2022
1 parent e860a81 commit 23f450f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,22 @@ macro_rules! system {
}
}

impl<D, Ul, Ur, V> $crate::lib::ops::$MulDivAssignTrait<Quantity<DimensionOne, Ur, V>> for Quantity<D, Ul, V>
where
D: Dimension + ?Sized,
D::Kind: $crate::marker::$MulDivAssignTrait,
Ul: Units<V> + ?Sized,
Ur: Units<V> + ?Sized,
V: $crate::num::Num + $crate::Conversion<V>
+ $crate::lib::ops::$MulDivAssignTrait<V>,
{
#[inline(always)]
fn $muldivassign_fun(&mut self, rhs: Quantity<DimensionOne, Ur, V>) {
self.value $muldivassign_op rhs.value;
// change_base is needed for autoconvert! version
}
}

#[doc(hidden)]
mod $Mod {
storage_types! {
Expand Down
8 changes: 4 additions & 4 deletions src/tests/impl_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ mod vv {
test!(div_ratio_right m(6.) / ratio(2.), m(3.)); // 6 c.f. BBB below
test!(mul_ratio_right_p m(4.) * pct(50.), m(2.)); // 6 c.f. CCC below
test!(div_ratio_right_p m(4.) / pct(50.), m(8.)); // 6 c.f. DDD below
// test!(mul_assign_ratio [ m(4.) ] *= ratio(2.), m(8.)); // ERR c.f. AAA above
// test!(div_assign_ratio [ m(6.) ] /= ratio(2.), m(3.)); // ERR c.f. BBB above
// test!(mul_assign_ratio_p [ m(4.) ] *= pct(50.), m(4.)); // ERR c.f. CCC above
// test!(div_assign_ratio_p [ m(4.) ] /= pct(50.), m(8.)); // ERR c.f. DDD above
test!(mul_assign_ratio [ m(4.) ] *= ratio(2.), m(8.)); // c.f. AAA above
test!(div_assign_ratio [ m(6.) ] /= ratio(2.), m(3.)); // c.f. BBB above
test!(mul_assign_ratio_p [ m(4.) ] *= pct(50.), m(2.)); // c.f. CCC above
test!(div_assign_ratio_p [ m(4.) ] /= pct(50.), m(8.)); // c.f. DDD above
test!(mul_bare_right m(4.) * 2. , m(8.)); // 7
test!(div_bare_right m(6.) / 2. , m(3.)); // 7
test!(mul_assign_bare [ m(2.) ] *= 3. , m(6.)); // 8
Expand Down

0 comments on commit 23f450f

Please sign in to comment.