mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 04:44:27 +02:00
feat: sqrt()
and cbrt()
added for dimension
, quantity_spec
, and unit
This commit is contained in:
@@ -189,6 +189,25 @@ template<std::intmax_t Num, std::intmax_t Den = 1, Dimension D>
|
|||||||
detail::type_list_of_base_dimension_less>(d);
|
detail::type_list_of_base_dimension_less>(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Computes the square root of a dimension
|
||||||
|
*
|
||||||
|
* @param d Dimension being the base of the operation
|
||||||
|
*
|
||||||
|
* @return Dimension The result of computation
|
||||||
|
*/
|
||||||
|
[[nodiscard]] consteval Dimension auto sqrt(Dimension auto d) { return pow<1, 2>(d); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Computes the cubic root of a dimension
|
||||||
|
*
|
||||||
|
* @param d Dimension being the base of the operation
|
||||||
|
*
|
||||||
|
* @return Dimension The result of computation
|
||||||
|
*/
|
||||||
|
[[nodiscard]] consteval Dimension auto cbrt(Dimension auto d) { return pow<1, 3>(d); }
|
||||||
|
|
||||||
|
|
||||||
// TODO consider adding the support for text output of the dimensional equation
|
// TODO consider adding the support for text output of the dimensional equation
|
||||||
|
|
||||||
} // namespace mp_units
|
} // namespace mp_units
|
||||||
|
@@ -556,6 +556,27 @@ template<std::intmax_t Num, std::intmax_t Den = 1, QuantitySpec Q>
|
|||||||
derived_quantity_spec<power<std::remove_const_t<decltype(remove_kind(Q{}))>, Num, Den>>{});
|
derived_quantity_spec<power<std::remove_const_t<decltype(remove_kind(Q{}))>, Num, Den>>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Computes the square root of a quantity specification
|
||||||
|
*
|
||||||
|
* @param q Quantity specification being the base of the operation
|
||||||
|
*
|
||||||
|
* @return QuantitySpec The result of computation
|
||||||
|
*/
|
||||||
|
[[nodiscard]] consteval QuantitySpec auto sqrt(QuantitySpec auto q) { return pow<1, 2>(q); }
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Computes the cubic root of a quantity specification
|
||||||
|
*
|
||||||
|
* @param q Quantity specification being the base of the operation
|
||||||
|
*
|
||||||
|
* @return QuantitySpec The result of computation
|
||||||
|
*/
|
||||||
|
[[nodiscard]] consteval QuantitySpec auto cbrt(QuantitySpec auto q) { return pow<1, 3>(q); }
|
||||||
|
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
enum class specs_convertible_result { no, cast, explicit_conversion, yes };
|
enum class specs_convertible_result { no, cast, explicit_conversion, yes };
|
||||||
|
@@ -569,6 +569,24 @@ template<std::intmax_t Num, std::intmax_t Den = 1, Unit U>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Computes the square root of a unit
|
||||||
|
*
|
||||||
|
* @param u Unit being the base of the operation
|
||||||
|
*
|
||||||
|
* @return Unit The result of computation
|
||||||
|
*/
|
||||||
|
[[nodiscard]] consteval Unit auto sqrt(Unit auto u) { return pow<1, 2>(u); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Computes the cubic root of a unit
|
||||||
|
*
|
||||||
|
* @param u Unit being the base of the operation
|
||||||
|
*
|
||||||
|
* @return Unit The result of computation
|
||||||
|
*/
|
||||||
|
[[nodiscard]] consteval Unit auto cbrt(Unit auto u) { return pow<1, 3>(u); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Computes the square power of a unit
|
* @brief Computes the square power of a unit
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user