From 28699c62c094833537b726f875375faba25b0c0a Mon Sep 17 00:00:00 2001 From: Jacek Generowicz Date: Thu, 18 Aug 2022 10:20:33 +0200 Subject: [PATCH] Implement MulDivAssign with Ratio on RHS --- src/system.rs | 16 ++++++++++++++++ src/tests/impl_ops.rs | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/system.rs b/src/system.rs index a9fb3b70..ff4322f7 100644 --- a/src/system.rs +++ b/src/system.rs @@ -553,6 +553,22 @@ macro_rules! system { } } + impl $crate::lib::ops::$MulDivAssignTrait> for Quantity + where + D: Dimension + ?Sized, + D::Kind: $crate::marker::$MulDivAssignTrait, + Ul: Units + ?Sized, + Ur: Units + ?Sized, + V: $crate::num::Num + $crate::Conversion + + $crate::lib::ops::$MulDivAssignTrait, + { + #[inline(always)] + fn $muldivassign_fun(&mut self, rhs: Quantity) { + self.value $muldivassign_op rhs.value; + // change_base is needed for autoconvert! version + } + } + #[doc(hidden)] mod $Mod { storage_types! { diff --git a/src/tests/impl_ops.rs b/src/tests/impl_ops.rs index 9e0974ba..f4ce55b0 100644 --- a/src/tests/impl_ops.rs +++ b/src/tests/impl_ops.rs @@ -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