diff --git a/src/include/units/bits/external/fixed_string.h b/src/include/units/bits/external/fixed_string.h index c3787cf8..e1d7e2db 100644 --- a/src/include/units/bits/external/fixed_string.h +++ b/src/include/units/bits/external/fixed_string.h @@ -27,6 +27,12 @@ namespace units { +/** + * @brief A compile-time fixed string + * + * @tparam CharT Character type to be used by the string + * @tparam N The size of the string + */ template struct basic_fixed_string { CharT data_[N + 1] = {}; diff --git a/src/include/units/concepts.h b/src/include/units/concepts.h index ce5bae13..435292f3 100644 --- a/src/include/units/concepts.h +++ b/src/include/units/concepts.h @@ -189,6 +189,14 @@ struct dimension_unit_impl { } // namespace detail +/** + * @brief Returns a 'default' unit of the dimension + * + * Depending on the dimension type it returns a base unit (for base dimensions) + * or a coherent unit (in case of derived dimensions). + * + * @tparam D Dimension type to get the unit from. + */ template using dimension_unit = detail::dimension_unit_impl::type; diff --git a/src/include/units/math.h b/src/include/units/math.h index 2d09be3f..4a55ba1a 100644 --- a/src/include/units/math.h +++ b/src/include/units/math.h @@ -29,13 +29,15 @@ namespace units { -template - requires(N == 0) -inline Rep pow(const quantity&) noexcept -{ - return 1; -} - +/** + * @brief Computes the value of a quantity raised to the power `N` + * + * Both the quantity value and its dimension are the base of the operation. + * + * @tparam N Exponent + * @param q Quantity being the base of the operation + * @return Quantity The result of computation + */ template requires(N != 0) inline Quantity AUTO pow(const quantity& q) noexcept @@ -47,6 +49,26 @@ inline Quantity AUTO pow(const quantity& q) noexcept return quantity(static_cast(std::pow(q.count(), N))); } +/** + * @brief OVerload that always returns 1 for N == 0 + * + * @return Rep A scalar value of @c 1. + */ +template + requires(N == 0) +inline Rep pow(const quantity&) noexcept +{ + return 1; +} + +/** + * @brief Computes the square root of a quantity + * + * Both the quantity value and its dimension are the base of the operation. + * + * @param q Quantity being the base of the operation + * @return Quantity The result of computation + */ template inline Quantity AUTO sqrt(const quantity& q) noexcept requires requires { std::sqrt(q.count()); } @@ -57,6 +79,12 @@ inline Quantity AUTO sqrt(const quantity& q) noexcept return quantity(static_cast(std::sqrt(q.count()))); } +/** + * @brief Computes the absolute value of a quantity + * + * @param q Quantity being the base of the operation + * @return Quantity The absolute value of a provided quantity + */ template constexpr Quantity AUTO abs(const quantity& q) noexcept requires requires { std::abs(q.count()); } @@ -64,6 +92,14 @@ constexpr Quantity AUTO abs(const quantity& q) noexcept return quantity(std::abs(q.count())); } +/** + * @brief Returns the epsilon of the quantity + * + * The returned value is defined by a std::numeric_limits::epsilon(). + * + * @tparam Q Quantity type being the base of the operation + * @return Quantity The epsilon value for quantity's representation type + */ template requires requires { std::numeric_limits::epsilon(); } constexpr Quantity AUTO epsilon() noexcept diff --git a/src/include/units/ratio.h b/src/include/units/ratio.h index b2bd0974..9495828f 100644 --- a/src/include/units/ratio.h +++ b/src/include/units/ratio.h @@ -33,6 +33,16 @@ namespace units { +/** + * @brief Provides compile-time rational arithmetic support. + * + * This class is really similar to @c std::ratio but gets an additional `Exp` + * template parameter. + * + * @tparam Num Numerator + * @tparam Den Denominator (default @c 1) + * @tparam Exp Exponent (default @c 0) + */ template requires(Den != 0) struct ratio { diff --git a/src/include/units/symbol_text.h b/src/include/units/symbol_text.h index 3aca1c45..e879bdaf 100644 --- a/src/include/units/symbol_text.h +++ b/src/include/units/symbol_text.h @@ -18,8 +18,20 @@ constexpr void validate_ascii_string([[maybe_unused]] const char (&s)[P + 1]) no #endif } -} +} // namespace detail + +/** + * @brief A symbol text representation + * + * This class template is responsible for definition and handling of a symbol text + * representation. In the libary it is used to define symbols of units and prefixes. + * Each symbol can have two versions: Unicode and ASCI-only. + * + * @tparam StandardCharT Character type to be used for a Unicode representation + * @tparam N The size of a Unicode symbol + * @tparam M The size of the ASCII-only symbol + */ template struct basic_symbol_text { basic_fixed_string standard_;