diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 57268ba0..925778b5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -14,6 +14,7 @@ - perf: temporary string creation removed from `quantity::op<<()` - perf: limited the C++ Standard Library headers usage - (!) fix: `exp()` has sense only for dimensionless quantities + - (!) fix: `dim_torque` now properly divides by an angle (instead of multiply) + default unit name change - fix: `quantity_cast()` fixed to work correctly with representation types not convertible from `std::intmax_t` - fix: ambiguous case for empty type list resolved - (!) build: The library should now be linked as `mp::units` in the CMake's `target_link_libraries()` diff --git a/example/experimental_angle.cpp b/example/experimental_angle.cpp index 49f17054..bc9777f7 100644 --- a/example/experimental_angle.cpp +++ b/example/experimental_angle.cpp @@ -33,10 +33,10 @@ using namespace units::physical::si::literals; int main() { - auto torque = 20.0_q_Nm; + auto torque = 20.0_q_Nm_per_rad; auto energy = 20.0_q_J; - Angle auto angle = torque / energy; + Angle auto angle = energy / torque; std::cout << angle << '\n'; } diff --git a/src/include/units/physical/dimensions/torque.h b/src/include/units/physical/dimensions/torque.h index b635306a..01e103e3 100644 --- a/src/include/units/physical/dimensions/torque.h +++ b/src/include/units/physical/dimensions/torque.h @@ -28,8 +28,8 @@ namespace units::physical { -template E, DimensionOfT A> -struct dim_torque : derived_dimension, exponent> {}; +template F, DimensionOfT L, DimensionOfT A> +struct dim_torque : derived_dimension, exponent, exponent> {}; template concept Torque = QuantityOfT; diff --git a/src/include/units/physical/si/derived/torque.h b/src/include/units/physical/si/derived/torque.h index f3b6f996..62949f1d 100644 --- a/src/include/units/physical/si/derived/torque.h +++ b/src/include/units/physical/si/derived/torque.h @@ -30,9 +30,9 @@ namespace units::physical::si { -struct newton_metre : named_unit {}; +struct newton_metre_per_radian : unit {}; -struct dim_torque : physical::dim_torque> {}; +struct dim_torque : physical::dim_torque> {}; template U, QuantityValue Rep = double> using torque = quantity; @@ -40,14 +40,14 @@ using torque = quantity; inline namespace literals { // Nm -constexpr auto operator"" _q_Nm(unsigned long long l) { return torque(l); } -constexpr auto operator"" _q_Nm(long double l) { return torque(l); } +constexpr auto operator"" _q_Nm_per_rad(unsigned long long l) { return torque(l); } +constexpr auto operator"" _q_Nm_per_rad(long double l) { return torque(l); } } // namespace literals namespace unit_constants { -inline constexpr auto Nm = torque{}; +inline constexpr auto Nm_per_rad = torque{}; } // namespace unit_constants diff --git a/test/unit_test/runtime/fmt_units_test.cpp b/test/unit_test/runtime/fmt_units_test.cpp index 5c2fee14..0afb9593 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -305,6 +305,11 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{}", 1_q_J_per_mol) == "1 J/mol"); } + SECTION("torque") + { + CHECK(fmt::format("{}", 1_q_Nm_per_rad) == "1 N ⋅ m/rad"); + } + SECTION("incoherent units with powers") { CHECK(fmt::format("{}", 1_q_mi * 1_q_mi * 1_q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³");