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, 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"); diff --git a/single-file-test.cc b/single-file-test.cc index 439b7552..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) { @@ -45,6 +47,10 @@ 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), + 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;