diff --git a/Cargo.toml b/Cargo.toml index 64c5d27..8fe70a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ num-traits = "0.2" typenum = "1.17" pyo3 = { version = "0.22", optional = true } numpy = { version = "0.22", optional = true } +num-dual = { version = "0.10", optional = true } [features] default = [] diff --git a/src/lib.rs b/src/lib.rs index 5bce2d1..03d749b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -443,6 +443,15 @@ impl Quantity { { &self.0 / unit.0 } + + /// Convert a quantity into the given unit and return it + /// as a float or array. + pub fn convert_into(self, unit: Quantity) -> Quot + where + T: Div, + { + self.0 / unit.0 + } } impl Zero for Quantity { @@ -454,3 +463,15 @@ impl Zero for Quantity { self.0.is_zero() } } + +#[cfg(feature = "num-dual")] +mod num_dual { + use super::Quantity; + use num_dual::DualNum; + + impl, U> Quantity { + pub fn re(&self) -> Quantity { + Quantity::new(self.0.re()) + } + } +}