From f3495d457f5efbd3e937cea7db2f1e8020d7994a Mon Sep 17 00:00:00 2001 From: printfn Date: Sun, 7 Jan 2024 07:10:15 +0000 Subject: [PATCH] Fix unit simplification bug (see #257) --- core/src/num/unit.rs | 5 +---- core/tests/integration_tests.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/num/unit.rs b/core/src/num/unit.rs index a80b9e93..a2b58d45 100644 --- a/core/src/num/unit.rs +++ b/core/src/num/unit.rs @@ -753,10 +753,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", + ); +}