From 72bc4c469c3028b7bfefbffbce409f7ad96f746e Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Wed, 18 Dec 2024 10:01:11 -0500 Subject: [PATCH 1/5] Add coverage for `is_known_to_be_less_than_one` --- single-file-test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/single-file-test.cc b/single-file-test.cc index 439b7552..fee14f5a 100644 --- a/single-file-test.cc +++ b/single-file-test.cc @@ -45,6 +45,7 @@ int main(int argc, char **argv) { { expect_equal((meters / second)(5) * seconds(6), meters(30)), expect_equal(SPEED_OF_LIGHT.as(m / s), 299'792'458 * m / s), + expect_equal((10 * m).coerce_in(m * mag<5>() / mag<7>()), 14), }, }; return std::all_of(std::begin(results), std::end(results), [](auto x) { return x; }) ? 0 : 1; From eb7e8c232ff429693f914ab181a84b991fe7b44e Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Wed, 18 Dec 2024 11:23:33 -0500 Subject: [PATCH 2/5] Try more direct test cases I thought the earlier test case would fail, but it didn't! --- single-file-test.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/single-file-test.cc b/single-file-test.cc index fee14f5a..8674b4c4 100644 --- a/single-file-test.cc +++ b/single-file-test.cc @@ -45,6 +45,8 @@ int main(int argc, char **argv) { { expect_equal((meters / second)(5) * seconds(6), meters(30)), expect_equal(SPEED_OF_LIGHT.as(m / s), 299'792'458 * m / s), + expect_equal(detail::is_known_to_be_less_than_one(mag<5>() / mag<7>()), true), + expect_equal(detail::is_known_to_be_less_than_one(mag<7>() / mag<5>()), false), expect_equal((10 * m).coerce_in(m * mag<5>() / mag<7>()), 14), }, }; From 70bb56214337bacc80d3ebf4f7ddf47f24ade3f1 Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Wed, 18 Dec 2024 11:25:26 -0500 Subject: [PATCH 3/5] "Fix" it anyway for stylistic consistency --- au/code/au/apply_rational_magnitude_to_integral.hh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/au/code/au/apply_rational_magnitude_to_integral.hh b/au/code/au/apply_rational_magnitude_to_integral.hh index 111d0beb..c7d7a738 100644 --- a/au/code/au/apply_rational_magnitude_to_integral.hh +++ b/au/code/au/apply_rational_magnitude_to_integral.hh @@ -75,9 +75,9 @@ constexpr T clamp_to_range_of(U x) { // template -constexpr bool is_known_to_be_less_than_one(Magnitude m) { +constexpr bool is_known_to_be_less_than_one(Magnitude) { using MagT = Magnitude; - static_assert(is_rational(m), "Magnitude must be rational"); + static_assert(is_rational(MagT{}), "Magnitude must be rational"); constexpr auto num_result = get_value_result(numerator(MagT{})); static_assert(num_result.outcome == MagRepresentationOutcome::OK, From 490aef896f1de4b3c1273b2c2d91c004d2f68b0b Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Wed, 18 Dec 2024 10:18:58 -0500 Subject: [PATCH 4/5] Cover `inverse_as` --- single-file-test.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/single-file-test.cc b/single-file-test.cc index 8674b4c4..0ef9e02c 100644 --- a/single-file-test.cc +++ b/single-file-test.cc @@ -29,6 +29,8 @@ using namespace au; using ::au::symbols::m; using ::au::symbols::s; +constexpr auto ns = ::au::nano(s); + // This ad hoc utility is a stand-in for GTEST, which we can't use here. template bool expect_equal(ExpectedT expected, ActualT actual) { @@ -48,6 +50,7 @@ int main(int argc, char **argv) { expect_equal(detail::is_known_to_be_less_than_one(mag<5>() / mag<7>()), true), expect_equal(detail::is_known_to_be_less_than_one(mag<7>() / mag<5>()), false), expect_equal((10 * m).coerce_in(m * mag<5>() / mag<7>()), 14), + expect_equal(inverse_as(ns, 333 / s), 3'003'003 * ns), }, }; return std::all_of(std::begin(results), std::end(results), [](auto x) { return x; }) ? 0 : 1; From 0faac6e0e4831edcc36bb70ea5529d75bc071625 Mon Sep 17 00:00:00 2001 From: Chip Hogg Date: Wed, 18 Dec 2024 11:27:41 -0500 Subject: [PATCH 5/5] Fix `inverse_as` --- au/code/au/math.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/au/code/au/math.hh b/au/code/au/math.hh index b61b7aaf..90d61dfc 100644 --- a/au/code/au/math.hh +++ b/au/code/au/math.hh @@ -256,7 +256,7 @@ constexpr auto inverse_in(TargetUnits target_units, Quantity q) { constexpr auto UNITY = make_constant(UnitProductT<>{}); static_assert( - UNITY.in(associated_unit(target_units) * U{}) >= threshold || + UNITY.in(associated_unit(TargetUnits{}) * U{}) >= threshold || std::is_floating_point::value, "Dangerous inversion risking truncation to 0; must supply explicit Rep if truly desired");