IAP GITLAB

Commit c24339ce authored by Maximilian Reininghaus's avatar Maximilian Reininghaus 🖖

Merge branch 'units-sqrt-pow' into 'master'

use std::sqrt() for sqrt(Quantity)

See merge request !342
parents ae6c0ada bff7db8f
Pipeline #4056 passed with stages
in 28 minutes and 26 seconds
......@@ -468,6 +468,9 @@ namespace phys {
template <typename D, typename X>
friend detail::Root<D, 2, X> sqrt(quantity<D, X> const& x);
template <typename D, typename X>
friend detail::Root<D, 3, X> cbrt(quantity<D, X> const& x);
// comparison
template <typename D, typename X, typename Y>
......@@ -676,7 +679,17 @@ namespace phys {
static_assert(detail::root<D, 2, X>::all_even_multiples,
"root result dimensions must be integral");
return detail::Root<D, 2, X>(std::pow(x.m_value, X(1.0) / 2));
return detail::Root<D, 2, X>(std::sqrt(x.m_value));
}
/// cubic root.
template <typename D, typename X>
detail::Root<D, 3, X> cbrt(quantity<D, X> const& x) {
static_assert(detail::root<D, 3, X>::all_even_multiples,
"root result dimensions must be integral");
return detail::Root<D, 3, X>(std::cbrt(x.m_value));
}
// Comparison operators
......
......@@ -92,6 +92,9 @@ TEST_CASE("PhysicalUnits", "[Units]") {
const auto E3 = E2 + 100_GeV + pow(10, lgE) * 1_GeV;
CHECK(E3 == 180_GeV);
CHECK(sqrt(5_GeV * 5_GeV) / 5_GeV == Approx(1));
CHECK(cbrt(static_pow<3>(5_GeV)) / 5_GeV == Approx(1));
}
SECTION("Output") {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment