Skip to content

Commit

Permalink
Fix unit simplification bug (see #257)
Browse files Browse the repository at this point in the history
  • Loading branch information
printfn committed Jan 7, 2024
1 parent bdec65a commit 363e7cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions core/src/num/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use super::Exact;

#[derive(Clone)]
pub(crate) struct Value {
#[allow(clippy::struct_field_names)]
value: Dist,
unit: Unit,
exact: bool,
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions core/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
}

0 comments on commit 363e7cb

Please sign in to comment.