mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 20:34:26 +02:00
fix: 💥 dim_torque
now properly divides by an angle (instead of multiply) + default unit name change
Resolves #220
This commit is contained in:
@@ -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()`
|
||||
|
@@ -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';
|
||||
}
|
||||
|
@@ -28,8 +28,8 @@
|
||||
|
||||
namespace units::physical {
|
||||
|
||||
template<typename Child, Unit U, DimensionOfT<dim_energy> E, DimensionOfT<dim_angle> A>
|
||||
struct dim_torque : derived_dimension<Child, U, exponent<E, 1>, exponent<A, 1>> {};
|
||||
template<typename Child, Unit U, DimensionOfT<dim_force> F, DimensionOfT<dim_length> L, DimensionOfT<dim_angle> A>
|
||||
struct dim_torque : derived_dimension<Child, U, exponent<F, 1>, exponent<L, 1>, exponent<A, -1>> {};
|
||||
|
||||
template<typename T>
|
||||
concept Torque = QuantityOfT<T, dim_torque>;
|
||||
|
@@ -30,9 +30,9 @@
|
||||
|
||||
namespace units::physical::si {
|
||||
|
||||
struct newton_metre : named_unit<newton_metre, "Nm", prefix> {};
|
||||
struct newton_metre_per_radian : unit<newton_metre_per_radian> {};
|
||||
|
||||
struct dim_torque : physical::dim_torque<dim_torque, newton_metre, dim_energy, dim_angle<>> {};
|
||||
struct dim_torque : physical::dim_torque<dim_torque, newton_metre_per_radian, dim_force, dim_length, dim_angle<>> {};
|
||||
|
||||
template<UnitOf<dim_torque> U, QuantityValue Rep = double>
|
||||
using torque = quantity<dim_torque, U, Rep>;
|
||||
@@ -40,14 +40,14 @@ using torque = quantity<dim_torque, U, Rep>;
|
||||
inline namespace literals {
|
||||
|
||||
// Nm
|
||||
constexpr auto operator"" _q_Nm(unsigned long long l) { return torque<newton_metre, std::int64_t>(l); }
|
||||
constexpr auto operator"" _q_Nm(long double l) { return torque<newton_metre, long double>(l); }
|
||||
constexpr auto operator"" _q_Nm_per_rad(unsigned long long l) { return torque<newton_metre_per_radian, std::int64_t>(l); }
|
||||
constexpr auto operator"" _q_Nm_per_rad(long double l) { return torque<newton_metre_per_radian, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
namespace unit_constants {
|
||||
|
||||
inline constexpr auto Nm = torque<newton_metre, one_rep>{};
|
||||
inline constexpr auto Nm_per_rad = torque<newton_metre_per_radian, one_rep>{};
|
||||
|
||||
} // namespace unit_constants
|
||||
|
||||
|
@@ -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³");
|
||||
|
Reference in New Issue
Block a user