From 4bcdc9f2c29b2625beef34039c2ce52216f07c6b Mon Sep 17 00:00:00 2001 From: Philipp Rehner <69816385+prehner@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:06:46 +0200 Subject: [PATCH] fix (#66) --- Cargo.toml | 1 + src/lib.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) 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()) + } + } +}