mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 20:54:28 +02:00
Measurement example updated
This commit is contained in:
@@ -40,8 +40,7 @@ public:
|
|||||||
|
|
||||||
measurement() = default;
|
measurement() = default;
|
||||||
|
|
||||||
constexpr /* explicit */ measurement(const value_type& val, const value_type& err = {}) :
|
constexpr explicit measurement(const value_type& val, const value_type& err = {}) :
|
||||||
// cannot be explicit as `magma` concept requires implicit conversions :-(
|
|
||||||
value_(val),
|
value_(val),
|
||||||
uncertainty_(std::abs(err))
|
uncertainty_(std::abs(err))
|
||||||
{
|
{
|
||||||
@@ -72,12 +71,36 @@ public:
|
|||||||
return measurement(val, val * rss(lhs.relative_uncertainty(), rhs.relative_uncertainty()));
|
return measurement(val, val * rss(lhs.relative_uncertainty(), rhs.relative_uncertainty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] friend constexpr measurement operator*(const measurement& lhs, const value_type& value)
|
||||||
|
{
|
||||||
|
const auto val = lhs.value() * value;
|
||||||
|
return measurement(val, val * lhs.relative_uncertainty());
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] friend constexpr measurement operator*(const value_type& value, const measurement& rhs)
|
||||||
|
{
|
||||||
|
const auto val = rhs.value() * value;
|
||||||
|
return measurement(val, val * rhs.relative_uncertainty());
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] friend constexpr measurement operator/(const measurement& lhs, const measurement& rhs)
|
[[nodiscard]] friend constexpr measurement operator/(const measurement& lhs, const measurement& rhs)
|
||||||
{
|
{
|
||||||
const auto val = lhs.value() / rhs.value();
|
const auto val = lhs.value() / rhs.value();
|
||||||
return measurement(val, val * rss(lhs.relative_uncertainty(), rhs.relative_uncertainty()));
|
return measurement(val, val * rss(lhs.relative_uncertainty(), rhs.relative_uncertainty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] friend constexpr measurement operator/(const measurement& lhs, const value_type& value)
|
||||||
|
{
|
||||||
|
const auto val = lhs.value() / value;
|
||||||
|
return measurement(val, val * lhs.relative_uncertainty());
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] friend constexpr measurement operator/(const value_type& value, const measurement& rhs)
|
||||||
|
{
|
||||||
|
const auto val = value / rhs.value();
|
||||||
|
return measurement(val, val * rhs.relative_uncertainty());
|
||||||
|
}
|
||||||
|
|
||||||
#if __GNUC__ >= 10
|
#if __GNUC__ >= 10
|
||||||
|
|
||||||
[[nodiscard]] friend constexpr auto operator<=>(const measurement& lhs, const measurement& rhs) = default;
|
[[nodiscard]] friend constexpr auto operator<=>(const measurement& lhs, const measurement& rhs) = default;
|
||||||
|
Reference in New Issue
Block a user