mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 19:04:27 +02:00
math_test enabled
This commit is contained in:
@@ -408,8 +408,13 @@ struct dimension_pow_impl<D, N> {
|
||||
using type = downcast<derived_dimension<exp<D, N>>>;
|
||||
};
|
||||
|
||||
template<BaseDimension D>
|
||||
struct dimension_pow_impl<D, 1> {
|
||||
using type = D;
|
||||
};
|
||||
|
||||
template<BaseDimension D, std::size_t N>
|
||||
struct dimension_pow_impl<exp<D, 1, N>, N> {
|
||||
struct dimension_pow_impl<derived_dimension<exp<D, 1, N>>, N> {
|
||||
using type = D;
|
||||
};
|
||||
|
||||
|
@@ -38,16 +38,18 @@ namespace units {
|
||||
inline Quantity AUTO pow(const quantity<D, U, Rep>& q) noexcept
|
||||
{
|
||||
using dim = dimension_pow<D, N>;
|
||||
using r = ratio_pow<typename U::ratio, N>;
|
||||
return quantity<dim, downcast<scaled_unit<typename dim::coherent_unit::reference, r>>, Rep>(static_cast<Rep>(std::pow(q.count(), N)));
|
||||
using ratio = ratio_pow<typename U::ratio, N>;
|
||||
using unit = detail::unit_for_dimension<dim, ratio>;
|
||||
return quantity<dim, unit, Rep>(static_cast<Rep>(std::pow(q.count(), N)));
|
||||
}
|
||||
|
||||
template<typename D, typename U, typename Rep>
|
||||
inline Quantity AUTO sqrt(const quantity<D, U, Rep>& q) noexcept
|
||||
{
|
||||
using dim = dimension_sqrt<typename U::dimension>;
|
||||
using r = ratio_sqrt<typename U::ratio>;
|
||||
return quantity<dim, downcast<scaled_unit<typename dim::coherent_unit::reference, r>>, Rep>(static_cast<Rep>(std::sqrt(q.count())));
|
||||
using dim = dimension_sqrt<D>;
|
||||
using ratio = ratio_sqrt<typename U::ratio>;
|
||||
using unit = detail::unit_for_dimension<dim, ratio>;
|
||||
return quantity<dim, unit, Rep>(static_cast<Rep>(std::sqrt(q.count())));
|
||||
}
|
||||
|
||||
} // namespace units
|
||||
|
@@ -25,7 +25,7 @@ add_library(unit_tests_static
|
||||
# custom_unit_test.cpp
|
||||
dimension_test.cpp
|
||||
# fixed_string_test.cpp
|
||||
# math_test.cpp
|
||||
math_test.cpp
|
||||
# new_design.cpp
|
||||
quantity_test.cpp
|
||||
ratio_test.cpp
|
||||
|
@@ -20,13 +20,13 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include "units/dimensions/area.h"
|
||||
#include "units/physical/si/area.h"
|
||||
#include "units/math.h"
|
||||
|
||||
using namespace units;
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace units::si::literals;
|
||||
|
||||
static_assert(std::is_same_v<decltype(pow<0>(2m)), std::int64_t>);
|
||||
static_assert(std::is_same_v<decltype(pow<1>(2m)), decltype(2m)>);
|
||||
static_assert(std::is_same_v<decltype(pow<2>(2m)), decltype(4sq_m)>);
|
||||
|
Reference in New Issue
Block a user