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 Sep 4, 2022
1 parent b8a211f commit 28699c6
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 @@ -173,10 +173,10 @@ mod vv {
test!( div_ratio_right m(6.) / one(2.), m(3.)); // 6 c.f. BBB below
test!(ac mul_ratio_right m(4.) * cgs_one(2.), m(8.)); // 6 c.f. CCC below
test!(ac div_ratio_right m(6.) / cgs_one(2.), m(3.)); // 6 c.f. DDD below
// test!( mul_assign_ratio [ m(4.) ] *= one(2.), m(8.)); // ERR c.f. AAA above
// test!( div_assign_ratio [ m(6.) ] /= one(2.), m(3.)); // ERR c.f. BBB above
// test!(ac mul_assign_ratio [ m(4.) ] *= cgs_one(2.), m(8.)); // ERR c.f. CCC above
// test!(ac div_assign_ratio [ m(6.) ] /= cgs_one(2.), m(3.)); // ERR c.f. DDD above
test!( mul_assign_ratio [ m(4.) ] *= one(2.), m(8.)); // c.f. AAA above
test!( div_assign_ratio [ m(6.) ] /= one(2.), m(3.)); // c.f. BBB above
test!(ac mul_assign_ratio [ m(4.) ] *= cgs_one(2.), m(8.)); // c.f. CCC above
test!(ac div_assign_ratio [ m(6.) ] /= cgs_one(2.), m(3.)); // 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 28699c6

Please sign in to comment.