feat: sqrt() and cbrt() added for dimension, quantity_spec, and unit

This commit is contained in:
Mateusz Pusz
2023-06-01 08:49:08 +02:00
parent 14258c97fd
commit 621faae8bc
3 changed files with 58 additions and 0 deletions

View File

@@ -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

View File

@@ -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 };

View File

@@ -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
* *