mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-02 11:54:27 +02:00
fix: inverse(Quantity)
fixed for subkinds of dimensionless
This commit is contained in:
@@ -444,12 +444,16 @@ template<Unit auto To, auto R, typename Rep>
|
|||||||
* @brief Computes the inverse of a quantity in a provided unit
|
* @brief Computes the inverse of a quantity in a provided unit
|
||||||
*/
|
*/
|
||||||
template<Unit auto To, auto R, typename Rep>
|
template<Unit auto To, auto R, typename Rep>
|
||||||
[[nodiscard]] constexpr QuantityOf<dimensionless / get_quantity_spec(R)> auto inverse(const quantity<R, Rep>& q)
|
[[nodiscard]] constexpr Quantity auto inverse(const quantity<R, Rep>& q)
|
||||||
requires requires {
|
requires requires {
|
||||||
representation_values<Rep>::one();
|
representation_values<Rep>::one();
|
||||||
value_cast<To>(representation_values<Rep>::one() / q);
|
value_cast<To>(representation_values<Rep>::one() / q);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
if constexpr (AssociatedUnit<MP_UNITS_REMOVE_CONST(decltype(To))>) {
|
||||||
|
constexpr QuantitySpec auto qs = get_quantity_spec(To) * quantity<R, Rep>::quantity_spec;
|
||||||
|
return qs(representation_values<Rep>::one() * one).force_in(To * quantity<R, Rep>::unit) / q;
|
||||||
|
} else
|
||||||
return (representation_values<Rep>::one() * one).force_in(To * quantity<R, Rep>::unit) / q;
|
return (representation_values<Rep>::one() * one).force_in(To * quantity<R, Rep>::unit) / q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user