From 363e7cb4ae5995bc56b4a9a7d89ec0829c731ef9 Mon Sep 17 00:00:00 2001 From: printfn Date: Sun, 7 Jan 2024 07:14:27 +0000 Subject: [PATCH] Fix unit simplification bug (see #257) --- core/src/num/unit.rs | 6 ++---- core/tests/integration_tests.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/num/unit.rs b/core/src/num/unit.rs index a80b9e93..1c46540b 100644 --- a/core/src/num/unit.rs +++ b/core/src/num/unit.rs @@ -26,6 +26,7 @@ use super::Exact; #[derive(Clone)] pub(crate) struct Value { + #[allow(clippy::struct_field_names)] value: Dist, unit: Unit, exact: bool, @@ -753,10 +754,7 @@ impl Value { exact: res_exact, } .mul( - &Exact { - value: comp.unit.scale.clone().into(), - exact: true, - }, + &comp.unit.scale.pow(comp.exponent, int)?.apply(Dist::from), int, )?; res_value = adjusted_res.value; diff --git a/core/tests/integration_tests.rs b/core/tests/integration_tests.rs index 2435de59..041e1665 100644 --- a/core/tests/integration_tests.rs +++ b/core/tests/integration_tests.rs @@ -5822,3 +5822,11 @@ fn simplification_ohms() { fn simplification_ohms_2() { test_eval("4556 volt / ampere", "4556 ohms"); } + +#[test] +fn alias_sqrt() { + test_eval( + "partial_result = 2*(0.84 femto meter) / (1.35e-22 m/s^2); sqrt(partial_result)", + "approx. 3527.6684147527 s", + ); +}