mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 12:24:26 +02:00
Missing op*() added
This commit is contained in:
@@ -258,14 +258,20 @@ public:
|
||||
[[nodiscard]] static constexpr quantity one() noexcept { return quantity(quantity_values<Rep>::one()); }
|
||||
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
requires treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
|
||||
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1)
|
||||
requires std::Same<typename U1::dimension, dim_invert_t<typename U2::dimension>>
|
||||
[[nodiscard]] constexpr Scalar operator*(const quantity<U1, Rep1>& lhs,
|
||||
const quantity<U2, Rep2>& rhs);
|
||||
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
requires (!std::Same<typename U1::dimension, dim_invert_t<typename U2::dimension>>) &&
|
||||
(treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
|
||||
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1))
|
||||
[[nodiscard]] constexpr Quantity operator*(const quantity<U1, Rep1>& lhs,
|
||||
const quantity<U2, Rep2>& rhs);
|
||||
|
||||
template<Scalar Rep1, typename U, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator/(const Rep1& v,
|
||||
const quantity<U, Rep2>& q)
|
||||
const quantity<U, Rep2>& q);
|
||||
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
requires std::Same<typename U1::dimension, typename U2::dimension>
|
||||
|
@@ -277,11 +277,22 @@ namespace std::experimental::units {
|
||||
return q * v;
|
||||
}
|
||||
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Scalar operator*(const quantity<U1, Rep1>& lhs,
|
||||
const quantity<U2, Rep2>& rhs)
|
||||
requires std::Same<typename U1::dimension, dim_invert_t<typename U2::dimension>>
|
||||
{
|
||||
using common_rep = decltype(lhs.count() * rhs.count());
|
||||
using ratio = ratio_multiply<typename U1::ratio, typename U2::ratio>;
|
||||
return common_rep(lhs.count()) * common_rep(rhs.count()) * common_rep(ratio::num) / common_rep(ratio::den);
|
||||
}
|
||||
|
||||
template<Unit U1, Scalar Rep1, Unit U2, Scalar Rep2>
|
||||
[[nodiscard]] constexpr Quantity operator*(const quantity<U1, Rep1>& lhs,
|
||||
const quantity<U2, Rep2>& rhs)
|
||||
requires treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
|
||||
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1)
|
||||
requires (!std::Same<typename U1::dimension, dim_invert_t<typename U2::dimension>>) &&
|
||||
(treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
|
||||
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1))
|
||||
{
|
||||
using dim = dimension_multiply_t<typename U1::dimension, typename U2::dimension>;
|
||||
using common_rep = decltype(lhs.count() * rhs.count());
|
||||
|
@@ -61,6 +61,7 @@ namespace {
|
||||
static_assert(1m == 1000mm);
|
||||
static_assert(1km + 1m == 1001m);
|
||||
static_assert(10km / 5km == 2);
|
||||
static_assert(100mm / 5cm == 2);
|
||||
static_assert(10km / 2 == 5km);
|
||||
|
||||
static_assert(1yd == 0.9144m);
|
||||
@@ -77,10 +78,11 @@ namespace {
|
||||
// frequency
|
||||
|
||||
static_assert(2 / 1s == 2Hz);
|
||||
static_assert(120 / 1min == 2Hz);
|
||||
static_assert(1000 / 1s == 1kHz);
|
||||
static_assert(1 / 1ms == 1kHz);
|
||||
static_assert(3.2GHz == 3'200'000'000Hz);
|
||||
// static_assert(10hz * 1min == 600);
|
||||
static_assert(10Hz * 1min == 600);
|
||||
|
||||
// force
|
||||
|
||||
|
Reference in New Issue
Block a user