diff --git a/linear_ops/Cargo.lock b/linear_ops/Cargo.lock index d88a4c6..6a24c51 100644 --- a/linear_ops/Cargo.lock +++ b/linear_ops/Cargo.lock @@ -29,6 +29,7 @@ name = "linear_ops" version = "0.1.0" dependencies = [ "fixed_wide", + "ratio_ops", ] [[package]] diff --git a/linear_ops/Cargo.toml b/linear_ops/Cargo.toml index 351534e..c2a73c3 100644 --- a/linear_ops/Cargo.toml +++ b/linear_ops/Cargo.toml @@ -6,6 +6,10 @@ edition = "2021" [features] default=["named-fields"] named-fields=[] +deferred-division=["dep:ratio_ops"] + +[dependencies] +ratio_ops = { path = "../ratio_ops", optional = true } [dev-dependencies] fixed_wide = { version = "0.1.0", path = "../fixed_wide" } diff --git a/linear_ops/src/macros/matrix.rs b/linear_ops/src/macros/matrix.rs index bc3866f..ead9f0a 100644 --- a/linear_ops/src/macros/matrix.rs +++ b/linear_ops/src/macros/matrix.rs @@ -127,6 +127,22 @@ macro_rules! impl_matrix { self.transform_vector(rhs) } } + #[cfg(feature="deferred-division")] + $crate::impl_matrix_deferred_division!(); + } +} + +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_matrix_deferred_division { + () => { + impl core::ops::Div for Matrix{ + type Output=ratio_ops::ratio::Ratio,U>; + #[inline] + fn div(self,rhs:U)->Self::Output{ + ratio_ops::ratio::Ratio::new(self,rhs) + } + } } } diff --git a/linear_ops/src/macros/vector.rs b/linear_ops/src/macros/vector.rs index cf1714f..2cd63fb 100644 --- a/linear_ops/src/macros/vector.rs +++ b/linear_ops/src/macros/vector.rs @@ -146,7 +146,10 @@ macro_rules! impl_vector { $crate::impl_vector_assign_operator_scalar!(MulAssign, mul_assign ); $crate::impl_vector_operator_scalar!(Mul, mul ); $crate::impl_vector_assign_operator_scalar!(DivAssign, div_assign ); + #[cfg(not(feature="deferred-division"))] $crate::impl_vector_operator_scalar!(Div, div ); + #[cfg(feature="deferred-division")] + $crate::impl_vector_deferred_division!(); // Impl bitwise operators $crate::impl_vector_assign_operator!(BitAndAssign, bitand_assign ); @@ -165,6 +168,19 @@ macro_rules! impl_vector { } #[doc(hidden)] #[macro_export(local_inner_macros)] +macro_rules! impl_vector_deferred_division { + () => { + impl core::ops::Div for Vector{ + type Output=ratio_ops::ratio::Ratio,U>; + #[inline] + fn div(self,rhs:U)->Self::Output{ + ratio_ops::ratio::Ratio::new(self,rhs) + } + } + } +} +#[doc(hidden)] +#[macro_export(local_inner_macros)] macro_rules! impl_vector_operator_scalar { ($trait: ident, $method: ident ) => { impl,U:Copy,V> core::ops::$trait for Vector{