Skip to content

Commit

Permalink
Inverse unit multiplier conversion (#166)
Browse files Browse the repository at this point in the history
* On more_atomic_units: inverse_units_test

* Add a test for converting to inverse units with multipliers

* Automated formatting of repo files (#170)

Co-authored-by: Philip Top <[email protected]>
Co-authored-by: HELICS-bot <[email protected]>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: HELICS-bot <[email protected]>
  • Loading branch information
3 people authored Sep 13, 2021
1 parent dc1ff97 commit 772a3da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test/test_conversions1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ TEST(UnitDefinitions, inversionConversion)
EXPECT_NEAR(convert(0.5, m, m.inv()), 2.0, test::tolerance);

EXPECT_NEAR(convert(10, Hz, s), 0.1, test::tolerance);

EXPECT_FLOAT_EQ(convert(1.0, kilo * Hz, milli * s), 1.0);
EXPECT_FLOAT_EQ(convert(1.0, milli * s, Hz), 1000.0);
EXPECT_FLOAT_EQ(convert(50.0, micro * s, kilo * Hz), 20.0);
EXPECT_FLOAT_EQ(convert(20000, kilo * Hz, nano * s), 50.0);
}

TEST(quickConvert, simple)
Expand Down
2 changes: 1 addition & 1 deletion units/units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ double convert(double val, const UX& start, const UX2& result)
if (base_start.has_same_base(base_result.inv())) {
// ignore flag and e flag special cases have been dealt with already,
// so those are just markers
return result.multiplier() / (val * start.multiplier());
return 1.0 / (val * start.multiplier() * result.multiplier());
}
if (start.has_e_flag() || result.has_e_flag()) {
double converted_val =
Expand Down

0 comments on commit 772a3da

Please sign in to comment.