mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-29 18:07:16 +02:00
refactor: relative()
renamed to delta()
This commit is contained in:
@ -62,14 +62,13 @@ int main()
|
||||
using estimate = kalman::system_state_estimate<qp>;
|
||||
using state = estimate::state_type;
|
||||
|
||||
const quantity process_noise_variance = 0.0001 * relative(pow<2>(deg_C));
|
||||
const estimate initial{state{qp{60. * relative(deg_C)}}, 100. * relative(deg_C)};
|
||||
const std::array measurements = {qp{49.986 * relative(deg_C)}, qp{49.963 * relative(deg_C)},
|
||||
qp{50.097 * relative(deg_C)}, qp{50.001 * relative(deg_C)},
|
||||
qp{50.018 * relative(deg_C)}, qp{50.05 * relative(deg_C)},
|
||||
qp{49.938 * relative(deg_C)}, qp{49.858 * relative(deg_C)},
|
||||
qp{49.965 * relative(deg_C)}, qp{50.114 * relative(deg_C)}};
|
||||
const quantity measurement_error = 0.1 * relative(deg_C);
|
||||
const quantity process_noise_variance = 0.0001 * delta(pow<2>(deg_C));
|
||||
const estimate initial{state{qp{60. * delta(deg_C)}}, 100. * delta(deg_C)};
|
||||
const std::array measurements = {qp{49.986 * delta(deg_C)}, qp{49.963 * delta(deg_C)}, qp{50.097 * delta(deg_C)},
|
||||
qp{50.001 * delta(deg_C)}, qp{50.018 * delta(deg_C)}, qp{50.05 * delta(deg_C)},
|
||||
qp{49.938 * delta(deg_C)}, qp{49.858 * delta(deg_C)}, qp{49.965 * delta(deg_C)},
|
||||
qp{50.114 * delta(deg_C)}};
|
||||
const quantity measurement_error = 0.1 * delta(deg_C);
|
||||
const quantity measurement_variance = pow<2>(measurement_error);
|
||||
|
||||
auto predict = [=](const estimate& current) {
|
||||
|
@ -62,14 +62,13 @@ int main()
|
||||
using estimate = kalman::system_state_estimate<qp>;
|
||||
using state = estimate::state_type;
|
||||
|
||||
const quantity process_noise_variance = 0.0001 * relative(pow<2>(deg_C));
|
||||
const estimate initial{state{qp{10. * relative(deg_C)}}, 100. * relative(deg_C)};
|
||||
const std::array measurements = {qp{50.486 * relative(deg_C)}, qp{50.963 * relative(deg_C)},
|
||||
qp{51.597 * relative(deg_C)}, qp{52.001 * relative(deg_C)},
|
||||
qp{52.518 * relative(deg_C)}, qp{53.05 * relative(deg_C)},
|
||||
qp{53.438 * relative(deg_C)}, qp{53.858 * relative(deg_C)},
|
||||
qp{54.465 * relative(deg_C)}, qp{55.114 * relative(deg_C)}};
|
||||
const quantity measurement_error = 0.1 * relative(deg_C);
|
||||
const quantity process_noise_variance = 0.0001 * delta(pow<2>(deg_C));
|
||||
const estimate initial{state{qp{10. * delta(deg_C)}}, 100. * delta(deg_C)};
|
||||
const std::array measurements = {qp{50.486 * delta(deg_C)}, qp{50.963 * delta(deg_C)}, qp{51.597 * delta(deg_C)},
|
||||
qp{52.001 * delta(deg_C)}, qp{52.518 * delta(deg_C)}, qp{53.05 * delta(deg_C)},
|
||||
qp{53.438 * delta(deg_C)}, qp{53.858 * delta(deg_C)}, qp{54.465 * delta(deg_C)},
|
||||
qp{55.114 * delta(deg_C)}};
|
||||
const quantity measurement_error = 0.1 * delta(deg_C);
|
||||
const quantity measurement_variance = pow<2>(measurement_error);
|
||||
|
||||
auto predict = [=](const estimate& current) {
|
||||
|
@ -62,14 +62,13 @@ int main()
|
||||
using estimate = kalman::system_state_estimate<qp>;
|
||||
using state = estimate::state_type;
|
||||
|
||||
const quantity process_noise_variance = 0.15 * relative(pow<2>(deg_C));
|
||||
const estimate initial{state{qp{10. * relative(deg_C)}}, 100. * relative(deg_C)};
|
||||
const std::array measurements = {qp{50.486 * relative(deg_C)}, qp{50.963 * relative(deg_C)},
|
||||
qp{51.597 * relative(deg_C)}, qp{52.001 * relative(deg_C)},
|
||||
qp{52.518 * relative(deg_C)}, qp{53.05 * relative(deg_C)},
|
||||
qp{53.438 * relative(deg_C)}, qp{53.858 * relative(deg_C)},
|
||||
qp{54.465 * relative(deg_C)}, qp{55.114 * relative(deg_C)}};
|
||||
const quantity measurement_error = 0.1 * relative(deg_C);
|
||||
const quantity process_noise_variance = 0.15 * delta(pow<2>(deg_C));
|
||||
const estimate initial{state{qp{10. * delta(deg_C)}}, 100. * delta(deg_C)};
|
||||
const std::array measurements = {qp{50.486 * delta(deg_C)}, qp{50.963 * delta(deg_C)}, qp{51.597 * delta(deg_C)},
|
||||
qp{52.001 * delta(deg_C)}, qp{52.518 * delta(deg_C)}, qp{53.05 * delta(deg_C)},
|
||||
qp{53.438 * delta(deg_C)}, qp{53.858 * delta(deg_C)}, qp{54.465 * delta(deg_C)},
|
||||
qp{55.114 * delta(deg_C)}};
|
||||
const quantity measurement_error = 0.1 * delta(deg_C);
|
||||
const quantity measurement_variance = pow<2>(measurement_error);
|
||||
|
||||
auto predict = [=](const estimate& current) {
|
||||
|
@ -84,7 +84,7 @@ int main()
|
||||
const auto t3 = std::make_tuple(isq::energy(q3 * h), isq::wavenumber(q3 / c), q3,
|
||||
isq::thermodynamic_temperature(q3 * h / kb), isq::wavelength(c / q3));
|
||||
|
||||
const auto q4 = isq::thermodynamic_temperature(1. * relative(K));
|
||||
const auto q4 = isq::thermodynamic_temperature(1. * delta(K));
|
||||
const auto t4 = std::make_tuple(isq::energy(q4 * kb), isq::wavenumber(q4 * kb / (h * c)), isq::frequency(q4 * kb / h),
|
||||
q4, isq::wavelength(h * c / (q4 * kb)));
|
||||
|
||||
|
@ -97,10 +97,10 @@ template<Quantity To, typename From>
|
||||
if constexpr (q_unit == To::unit) {
|
||||
// no scaling of the number needed
|
||||
return {static_cast<MP_UNITS_TYPENAME To::rep>(std::forward<From>(q).numerical_value_is_an_implementation_detail_),
|
||||
relative(To::reference)}; // this is the only (and recommended) way to do
|
||||
// a truncating conversion on a number, so we are
|
||||
// using static_cast to suppress all the compiler
|
||||
// warnings on conversions
|
||||
delta(To::reference)}; // this is the only (and recommended) way to do
|
||||
// a truncating conversion on a number, so we are
|
||||
// using static_cast to suppress all the compiler
|
||||
// warnings on conversions
|
||||
} else {
|
||||
// scale the number
|
||||
using traits = magnitude_conversion_traits<To, std::remove_reference_t<From>>;
|
||||
@ -108,13 +108,13 @@ template<Quantity To, typename From>
|
||||
// this results in great assembly
|
||||
auto res = static_cast<MP_UNITS_TYPENAME To::rep>(
|
||||
static_cast<traits::c_type>(q.numerical_value_is_an_implementation_detail_) * traits::ratio);
|
||||
return {res, relative(To::reference)};
|
||||
return {res, delta(To::reference)};
|
||||
} else {
|
||||
// this is slower but allows conversions like 2000 m -> 2 km without loosing data
|
||||
auto res = static_cast<MP_UNITS_TYPENAME To::rep>(
|
||||
static_cast<traits::c_type>(q.numerical_value_is_an_implementation_detail_) * traits::num_mult /
|
||||
traits::den_mult * traits::irr_mult);
|
||||
return {res, relative(To::reference)};
|
||||
return {res, delta(To::reference)};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ using common_quantity_for = quantity<common_reference(Q1::reference, Q2::referen
|
||||
std::invoke_result_t<Func, typename Q1::rep, typename Q2::rep>>;
|
||||
|
||||
template<typename T, typename R>
|
||||
concept SameOriginalReferenceAs = RelativeReference<T> && Reference<R> && (get_original_reference(T{}) == R{});
|
||||
concept SameOriginalReferenceAs = DeltaReference<T> && Reference<R> && (get_original_reference(T{}) == R{});
|
||||
|
||||
template<typename R1, typename R2, typename Rep1, typename Rep2>
|
||||
concept SameValueAs = detail::SameOriginalReferenceAs<R1, R2> && std::same_as<Rep1, Rep2>;
|
||||
@ -123,25 +123,25 @@ public:
|
||||
[[nodiscard]] static constexpr quantity zero() noexcept
|
||||
requires requires { quantity_values<rep>::zero(); }
|
||||
{
|
||||
return {quantity_values<rep>::zero(), relative(R)};
|
||||
return {quantity_values<rep>::zero(), delta(R)};
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr quantity one() noexcept
|
||||
requires requires { quantity_values<rep>::one(); }
|
||||
{
|
||||
return {quantity_values<rep>::one(), relative(R)};
|
||||
return {quantity_values<rep>::one(), delta(R)};
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr quantity min() noexcept
|
||||
requires requires { quantity_values<rep>::min(); }
|
||||
{
|
||||
return {quantity_values<rep>::min(), relative(R)};
|
||||
return {quantity_values<rep>::min(), delta(R)};
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr quantity max() noexcept
|
||||
requires requires { quantity_values<rep>::max(); }
|
||||
{
|
||||
return {quantity_values<rep>::max(), relative(R)};
|
||||
return {quantity_values<rep>::max(), delta(R)};
|
||||
}
|
||||
|
||||
// construction, assignment, destruction
|
||||
@ -150,13 +150,13 @@ public:
|
||||
quantity(quantity&&) = default;
|
||||
~quantity() = default;
|
||||
|
||||
template<typename Value, RelativeReference R2>
|
||||
template<typename Value, DeltaReference R2>
|
||||
requires detail::SameValueAs<R2, decltype(R), std::remove_cvref_t<Value>, Rep>
|
||||
constexpr quantity(Value&& v, R2) : numerical_value_is_an_implementation_detail_(std::forward<Value>(v))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Value, RelativeReference R2>
|
||||
template<typename Value, DeltaReference R2>
|
||||
requires(!detail::SameValueAs<R2, decltype(R), std::remove_cvref_t<Value>, Rep>) &&
|
||||
detail::QuantityConvertibleTo<quantity<R2{}, std::remove_cvref_t<Value>>, quantity>
|
||||
constexpr quantity(Value&& v, R2) :
|
||||
@ -179,8 +179,8 @@ public:
|
||||
convert_explicitly> ||
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
!std::convertible_to<typename quantity_like_traits<Q>::rep, Rep>) quantity(const Q& q) :
|
||||
quantity(
|
||||
::mp_units::quantity{quantity_like_traits<Q>::to_numerical_value(q).value, relative(quantity_like_traits<Q>::reference)})
|
||||
quantity(::mp_units::quantity{quantity_like_traits<Q>::to_numerical_value(q).value,
|
||||
delta(quantity_like_traits<Q>::reference)})
|
||||
{
|
||||
}
|
||||
|
||||
@ -274,7 +274,7 @@ public:
|
||||
} -> std::common_with<rep>;
|
||||
}
|
||||
{
|
||||
return ::mp_units::quantity{+numerical_value_is_an_implementation_detail_, relative(reference)};
|
||||
return ::mp_units::quantity{+numerical_value_is_an_implementation_detail_, delta(reference)};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr QuantityOf<quantity_spec> auto operator-() const
|
||||
@ -284,7 +284,7 @@ public:
|
||||
} -> std::common_with<rep>;
|
||||
}
|
||||
{
|
||||
return ::mp_units::quantity{-numerical_value_is_an_implementation_detail_, relative(reference)};
|
||||
return ::mp_units::quantity{-numerical_value_is_an_implementation_detail_, delta(reference)};
|
||||
}
|
||||
|
||||
template<typename Q>
|
||||
@ -306,7 +306,7 @@ public:
|
||||
} -> std::common_with<rep>;
|
||||
}
|
||||
{
|
||||
return ::mp_units::quantity{numerical_value_is_an_implementation_detail_++, relative(reference)};
|
||||
return ::mp_units::quantity{numerical_value_is_an_implementation_detail_++, delta(reference)};
|
||||
}
|
||||
|
||||
template<typename Q>
|
||||
@ -328,7 +328,7 @@ public:
|
||||
} -> std::common_with<rep>;
|
||||
}
|
||||
{
|
||||
return ::mp_units::quantity{numerical_value_is_an_implementation_detail_--, relative(reference)};
|
||||
return ::mp_units::quantity{numerical_value_is_an_implementation_detail_--, delta(reference)};
|
||||
}
|
||||
|
||||
// compound assignment operators
|
||||
@ -427,7 +427,7 @@ public:
|
||||
};
|
||||
|
||||
// CTAD
|
||||
template<typename Value, RelativeReference R>
|
||||
template<typename Value, DeltaReference R>
|
||||
requires RepresentationOf<Value, get_quantity_spec(detail::get_original_reference(R{})).character>
|
||||
quantity(Value v, R) -> quantity<detail::get_original_reference(R{}), Value>;
|
||||
|
||||
@ -445,7 +445,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
const ret ret_lhs(lhs);
|
||||
const ret ret_rhs(rhs);
|
||||
return quantity{ret_lhs.numerical_value_ref_in(ret::unit) + ret_rhs.numerical_value_ref_in(ret::unit),
|
||||
relative(ret::reference)};
|
||||
delta(ret::reference)};
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
@ -456,7 +456,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
const ret ret_lhs(lhs);
|
||||
const ret ret_rhs(rhs);
|
||||
return quantity{ret_lhs.numerical_value_ref_in(ret::unit) - ret_rhs.numerical_value_ref_in(ret::unit),
|
||||
relative(ret::reference)};
|
||||
delta(ret::reference)};
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
@ -469,15 +469,14 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
const ret ret_lhs(lhs);
|
||||
const ret ret_rhs(rhs);
|
||||
return quantity{ret_lhs.numerical_value_ref_in(ret::unit) % ret_rhs.numerical_value_ref_in(ret::unit),
|
||||
relative(ret::reference)};
|
||||
delta(ret::reference)};
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
requires detail::InvocableQuantities<std::multiplies<>, quantity<R1, Rep1>, quantity<R2, Rep2>>
|
||||
[[nodiscard]] constexpr Quantity auto operator*(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
return quantity{lhs.numerical_value_ref_in(get_unit(R1)) * rhs.numerical_value_ref_in(get_unit(R2)),
|
||||
relative(R1 * R2)};
|
||||
return quantity{lhs.numerical_value_ref_in(get_unit(R1)) * rhs.numerical_value_ref_in(get_unit(R2)), delta(R1 * R2)};
|
||||
}
|
||||
|
||||
template<auto R, typename Rep, typename Value>
|
||||
@ -485,7 +484,7 @@ template<auto R, typename Rep, typename Value>
|
||||
detail::InvokeResultOf<get_quantity_spec(R).character, std::multiplies<>, Rep, const Value&>
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(R)> auto operator*(const quantity<R, Rep>& q, const Value& v)
|
||||
{
|
||||
return quantity{q.numerical_value_ref_in(get_unit(R)) * v, relative(R)};
|
||||
return quantity{q.numerical_value_ref_in(get_unit(R)) * v, delta(R)};
|
||||
}
|
||||
|
||||
template<typename Value, auto R, typename Rep>
|
||||
@ -493,7 +492,7 @@ template<typename Value, auto R, typename Rep>
|
||||
detail::InvokeResultOf<get_quantity_spec(R).character, std::multiplies<>, const Value&, Rep>
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(R)> auto operator*(const Value& v, const quantity<R, Rep>& q)
|
||||
{
|
||||
return quantity{v * q.numerical_value_ref_in(get_unit(R)), relative(R)};
|
||||
return quantity{v * q.numerical_value_ref_in(get_unit(R)), delta(R)};
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
@ -501,8 +500,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
MP_UNITS_EXPECTS_DEBUG(rhs != rhs.zero());
|
||||
return quantity{lhs.numerical_value_ref_in(get_unit(R1)) / rhs.numerical_value_ref_in(get_unit(R2)),
|
||||
relative(R1 / R2)};
|
||||
return quantity{lhs.numerical_value_ref_in(get_unit(R1)) / rhs.numerical_value_ref_in(get_unit(R2)), delta(R1 / R2)};
|
||||
}
|
||||
|
||||
template<auto R, typename Rep, typename Value>
|
||||
@ -511,7 +509,7 @@ template<auto R, typename Rep, typename Value>
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(R)> auto operator/(const quantity<R, Rep>& q, const Value& v)
|
||||
{
|
||||
MP_UNITS_EXPECTS_DEBUG(v != quantity_values<Value>::zero());
|
||||
return quantity{q.numerical_value_ref_in(get_unit(R)) / v, relative(R)};
|
||||
return quantity{q.numerical_value_ref_in(get_unit(R)) / v, delta(R)};
|
||||
}
|
||||
|
||||
template<typename Value, auto R, typename Rep>
|
||||
@ -520,7 +518,7 @@ template<typename Value, auto R, typename Rep>
|
||||
[[nodiscard]] constexpr QuantityOf<inverse(get_quantity_spec(R))> auto operator/(const Value& v,
|
||||
const quantity<R, Rep>& q)
|
||||
{
|
||||
return quantity{v / q.numerical_value_ref_in(get_unit(R)), relative(::mp_units::one / R)};
|
||||
return quantity{v / q.numerical_value_ref_in(get_unit(R)), delta(::mp_units::one / R)};
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
|
@ -57,7 +57,7 @@ template<QuantitySpec auto ToQS, typename Q>
|
||||
[[nodiscard]] constexpr Quantity auto quantity_cast(Q&& q)
|
||||
{
|
||||
return quantity{std::forward<Q>(q).numerical_value_is_an_implementation_detail_,
|
||||
relative(make_reference(ToQS, std::remove_reference_t<Q>::unit))};
|
||||
delta(make_reference(ToQS, std::remove_reference_t<Q>::unit))};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,7 +129,7 @@ struct quantity_spec_interface {
|
||||
(explicitly_convertible(std::remove_reference_t<Q>::quantity_spec, self))
|
||||
{
|
||||
return quantity{std::forward<Q>(q).numerical_value_is_an_implementation_detail_,
|
||||
relative(detail::make_reference(self, std::remove_cvref_t<Q>::unit))};
|
||||
delta(detail::make_reference(self, std::remove_cvref_t<Q>::unit))};
|
||||
}
|
||||
#else
|
||||
template<typename Self_ = Self, UnitOf<Self_{}> U>
|
||||
@ -144,7 +144,7 @@ struct quantity_spec_interface {
|
||||
[[nodiscard]] constexpr Quantity auto operator()(Q&& q) const
|
||||
{
|
||||
return quantity{std::forward<Q>(q).numerical_value_is_an_implementation_detail_,
|
||||
relative(detail::make_reference(Self{}, std::remove_cvref_t<Q>::unit))};
|
||||
delta(detail::make_reference(Self{}, std::remove_cvref_t<Q>::unit))};
|
||||
}
|
||||
#endif
|
||||
};
|
||||
@ -341,7 +341,7 @@ struct quantity_spec<Self, QS, Args...> : detail::propagate_equation<QS>, detail
|
||||
[[nodiscard]] constexpr Quantity auto operator()(Q&& q) const
|
||||
{
|
||||
return quantity{std::forward<Q>(q).numerical_value_is_an_implementation_detail_,
|
||||
relative(detail::make_reference(Self{}, std::remove_cvref_t<Q>::unit))};
|
||||
delta(detail::make_reference(Self{}, std::remove_cvref_t<Q>::unit))};
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
@ -41,7 +41,7 @@ template<QuantitySpec auto Q, Unit auto U>
|
||||
using reference_t = reference<MP_UNITS_REMOVE_CONST(decltype(Q)), MP_UNITS_REMOVE_CONST(decltype(U))>;
|
||||
|
||||
template<typename R>
|
||||
requires RelativeReference<R> || AbsoluteReference<R>
|
||||
requires DeltaReference<R> || AbsoluteReference<R>
|
||||
[[nodiscard]] consteval Reference auto get_original_reference(R r)
|
||||
{
|
||||
if constexpr (requires { typename R::_type_; })
|
||||
@ -183,19 +183,19 @@ struct reference {
|
||||
};
|
||||
|
||||
|
||||
template<typename Rep, RelativeReference R>
|
||||
template<typename Rep, DeltaReference R>
|
||||
requires RepresentationOf<std::remove_cvref_t<Rep>, get_quantity_spec(detail::get_original_reference(R{})).character>
|
||||
[[nodiscard]] constexpr quantity<detail::get_original_reference(R{}), std::remove_cvref_t<Rep>> operator*(Rep&& lhs, R)
|
||||
{
|
||||
return quantity{std::forward<Rep>(lhs), R{}};
|
||||
}
|
||||
|
||||
template<typename Rep, RelativeReference R>
|
||||
template<typename Rep, DeltaReference R>
|
||||
requires RepresentationOf<std::remove_cvref_t<Rep>, get_quantity_spec(detail::get_original_reference(R{})).character>
|
||||
[[nodiscard]] constexpr quantity<inverse(detail::get_original_reference(R{})), std::remove_cvref_t<Rep>> operator/(
|
||||
Rep&& lhs, R)
|
||||
{
|
||||
return quantity{std::forward<Rep>(lhs), relative(inverse(detail::get_original_reference(R{})))};
|
||||
return quantity{std::forward<Rep>(lhs), delta(inverse(detail::get_original_reference(R{})))};
|
||||
}
|
||||
|
||||
template<typename Rep, AbsoluteReference R>
|
||||
@ -205,7 +205,7 @@ template<typename Rep, AbsoluteReference R>
|
||||
std::remove_cvref_t<Rep>>
|
||||
operator*(Rep&& lhs, R)
|
||||
{
|
||||
return quantity_point{std::forward<Rep>(lhs) * relative(detail::get_original_reference(R{}))};
|
||||
return quantity_point{std::forward<Rep>(lhs) * delta(detail::get_original_reference(R{}))};
|
||||
}
|
||||
|
||||
template<typename Rep, AbsoluteReference R>
|
||||
@ -215,7 +215,7 @@ template<typename Rep, AbsoluteReference R>
|
||||
std::remove_cvref_t<Rep>>
|
||||
operator/(Rep&& lhs, R)
|
||||
{
|
||||
return quantity_point{std::forward<Rep>(lhs) * relative(inverse(detail::get_original_reference(R{})))};
|
||||
return quantity_point{std::forward<Rep>(lhs) * delta(inverse(detail::get_original_reference(R{})))};
|
||||
}
|
||||
|
||||
template<Reference R, typename Rep>
|
||||
@ -233,7 +233,7 @@ template<typename Q, Reference R>
|
||||
[[nodiscard]] constexpr Quantity auto operator*(Q&& q, R)
|
||||
{
|
||||
return quantity{std::forward<Q>(q).numerical_value_is_an_implementation_detail_,
|
||||
relative(std::remove_cvref_t<Q>::reference * R{})};
|
||||
delta(std::remove_cvref_t<Q>::reference * R{})};
|
||||
}
|
||||
|
||||
template<typename Q, Reference R>
|
||||
@ -241,7 +241,7 @@ template<typename Q, Reference R>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(Q&& q, R)
|
||||
{
|
||||
return quantity{std::forward<Q>(q).numerical_value_is_an_implementation_detail_,
|
||||
relative(std::remove_cvref_t<Q>::reference / R{})};
|
||||
delta(std::remove_cvref_t<Q>::reference / R{})};
|
||||
}
|
||||
|
||||
template<Reference R, typename Q>
|
||||
|
@ -91,7 +91,7 @@ struct absolute_ final {
|
||||
};
|
||||
|
||||
template<Reference R>
|
||||
MP_UNITS_EXPORT [[nodiscard]] consteval relative_<R> relative(R)
|
||||
MP_UNITS_EXPORT [[nodiscard]] consteval relative_<R> delta(R)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
@ -103,7 +103,7 @@ MP_UNITS_EXPORT [[nodiscard]] consteval absolute_<R> absolute(R)
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
MP_UNITS_EXPORT concept RelativeReference =
|
||||
MP_UNITS_EXPORT concept DeltaReference =
|
||||
(Reference<T> && !requires { get_unit(T{}).point_origin; }) || is_specialization_of<T, relative_>;
|
||||
|
||||
template<typename T>
|
||||
|
@ -115,7 +115,7 @@ template<ReferenceOf<dimensionless> auto R, typename Rep>
|
||||
{
|
||||
using std::exp;
|
||||
return value_cast<get_unit(R)>(
|
||||
quantity{static_cast<Rep>(exp(q.force_numerical_value_in(q.unit))), relative(detail::clone_reference_with<one>(R))});
|
||||
quantity{static_cast<Rep>(exp(q.force_numerical_value_in(q.unit))), delta(detail::clone_reference_with<one>(R))});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -236,7 +236,7 @@ template<auto R, auto S, auto T, typename Rep1, typename Rep2, typename Rep3>
|
||||
using std::fma;
|
||||
return quantity{
|
||||
fma(a.numerical_value_ref_in(a.unit), x.numerical_value_ref_in(x.unit), b.numerical_value_ref_in(b.unit)),
|
||||
relative(common_reference(R * S, T))};
|
||||
delta(common_reference(R * S, T))};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -260,7 +260,7 @@ template<auto R, auto S, auto T, auto Origin, typename Rep1, typename Rep2, type
|
||||
using std::fma;
|
||||
return Origin + quantity{fma(a.numerical_value_ref_in(a.unit), x.numerical_value_ref_in(x.unit),
|
||||
b.quantity_ref_from(b.point_origin).numerical_value_ref_in(b.unit)),
|
||||
relative(common_reference(R * S, T))};
|
||||
delta(common_reference(R * S, T))};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -277,7 +277,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::fmod;
|
||||
return quantity{fmod(x.numerical_value_in(unit), y.numerical_value_in(unit)), relative(ref)};
|
||||
return quantity{fmod(x.numerical_value_in(unit), y.numerical_value_in(unit)), delta(ref)};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,7 +294,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::remainder;
|
||||
return quantity{remainder(x.numerical_value_in(unit), y.numerical_value_in(unit)), relative(ref)};
|
||||
return quantity{remainder(x.numerical_value_in(unit), y.numerical_value_in(unit)), delta(ref)};
|
||||
}
|
||||
|
||||
|
||||
@ -339,7 +339,7 @@ template<Unit auto To, auto R, typename Rep>
|
||||
return {static_cast<Rep>(floor(q.numerical_value_ref_in(q.unit))), detail::clone_reference_with<To>(R)};
|
||||
} else {
|
||||
return handle_signed_results(
|
||||
quantity{static_cast<Rep>(floor(q.force_numerical_value_in(To))), relative(detail::clone_reference_with<To>(R))});
|
||||
quantity{static_cast<Rep>(floor(q.force_numerical_value_in(To))), delta(detail::clone_reference_with<To>(R))});
|
||||
}
|
||||
} else {
|
||||
if constexpr (To == get_unit(R)) {
|
||||
@ -376,7 +376,7 @@ template<Unit auto To, auto R, typename Rep>
|
||||
return {static_cast<Rep>(ceil(q.numerical_value_ref_in(q.unit))), detail::clone_reference_with<To>(R)};
|
||||
} else {
|
||||
return handle_signed_results(
|
||||
quantity{static_cast<Rep>(ceil(q.force_numerical_value_in(To))), relative(detail::clone_reference_with<To>(R))});
|
||||
quantity{static_cast<Rep>(ceil(q.force_numerical_value_in(To))), delta(detail::clone_reference_with<To>(R))});
|
||||
}
|
||||
} else {
|
||||
if constexpr (To == get_unit(R)) {
|
||||
@ -456,7 +456,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::hypot;
|
||||
return quantity{hypot(x.numerical_value_in(unit), y.numerical_value_in(unit)), relative(ref)};
|
||||
return quantity{hypot(x.numerical_value_in(unit), y.numerical_value_in(unit)), delta(ref)};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -474,7 +474,8 @@ template<auto R1, typename Rep1, auto R2, typename Rep2, auto R3, typename Rep3>
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::hypot;
|
||||
return quantity{hypot(x.numerical_value_in(unit), y.numerical_value_in(unit), z.numerical_value_in(unit)), relative(ref)};
|
||||
return quantity{hypot(x.numerical_value_in(unit), y.numerical_value_in(unit), z.numerical_value_in(unit)),
|
||||
delta(ref)};
|
||||
}
|
||||
|
||||
} // namespace mp_units
|
||||
|
@ -77,7 +77,7 @@ inline constexpr struct weber final : named_unit<"Wb", volt * second> {} weber;
|
||||
inline constexpr struct tesla final : named_unit<"T", weber / square(metre)> {} tesla;
|
||||
inline constexpr struct henry final : named_unit<"H", weber / ampere> {} henry;
|
||||
|
||||
inline constexpr struct ice_point final : relative_point_origin<quantity_point{273'150 * relative(milli<kelvin>)}> {} ice_point;
|
||||
inline constexpr struct ice_point final : relative_point_origin<quantity_point{273'150 * delta(milli<kelvin>)}> {} ice_point;
|
||||
inline constexpr auto zeroth_degree_Celsius = ice_point;
|
||||
inline constexpr struct degree_Celsius final : named_unit<symbol_text{u8"°C", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius;
|
||||
|
||||
|
@ -118,7 +118,7 @@ inline constexpr struct troy_pound final : named_unit<"lb t", mag<12> * troy_onc
|
||||
inline constexpr struct inch_of_mercury final : named_unit<"inHg", mag_ratio<3'386'389, 1'000> * si::pascal> {} inch_of_mercury;
|
||||
|
||||
// https://en.wikipedia.org/wiki/United_States_customary_units#Temperature
|
||||
inline constexpr struct zeroth_degree_Fahrenheit final : relative_point_origin<quantity_point{-32 * relative(mag_ratio<5, 9> * si::degree_Celsius)}> {} zeroth_degree_Fahrenheit;
|
||||
inline constexpr struct zeroth_degree_Fahrenheit final : relative_point_origin<quantity_point{-32 * delta(mag_ratio<5, 9> * si::degree_Celsius)}> {} zeroth_degree_Fahrenheit;
|
||||
inline constexpr struct degree_Fahrenheit final : named_unit<symbol_text{u8"°F", "`F"}, mag_ratio<5, 9> * si::degree_Celsius, zeroth_degree_Fahrenheit> {} degree_Fahrenheit;
|
||||
|
||||
// clang-format on
|
||||
|
@ -803,10 +803,10 @@ static_assert(
|
||||
static_assert(quantity_point{42 * m}.quantity_from_zero() == 42 * m);
|
||||
static_assert((42 * absolute(m)).quantity_from_zero() == 42 * m);
|
||||
static_assert(quantity_point{isq::height(42 * m)}.quantity_from_zero() == 42 * m);
|
||||
static_assert(quantity_point{20 * relative(deg_C)}.quantity_from_zero() == 20 * relative(deg_C));
|
||||
static_assert((20 * absolute(deg_C)).quantity_from_zero() == 20 * relative(deg_C));
|
||||
static_assert(quantity_point{20. * relative(deg_C)}.in(deg_F).quantity_from_zero() == 68 * relative(deg_F));
|
||||
static_assert((20. * absolute(deg_C)).in(deg_F).quantity_from_zero() == 68 * relative(deg_F));
|
||||
static_assert(quantity_point{20 * delta(deg_C)}.quantity_from_zero() == 20 * delta(deg_C));
|
||||
static_assert((20 * absolute(deg_C)).quantity_from_zero() == 20 * delta(deg_C));
|
||||
static_assert(quantity_point{20. * delta(deg_C)}.in(deg_F).quantity_from_zero() == 68 * delta(deg_F));
|
||||
static_assert((20. * absolute(deg_C)).in(deg_F).quantity_from_zero() == 68 * delta(deg_F));
|
||||
|
||||
static_assert((mean_sea_level + 42 * m).quantity_from_zero() == 42 * m);
|
||||
static_assert((ground_level + 42 * m).quantity_from_zero() == 84 * m);
|
||||
|
@ -126,7 +126,7 @@ static_assert(isq::mass(1 * lb_t) == isq::mass(12 * oz_t));
|
||||
static_assert(isq::pressure(1'000 * inHg) == isq::pressure(3'386'389 * si::pascal));
|
||||
|
||||
// Temperature
|
||||
static_assert(isq::thermodynamic_temperature(9 * relative(deg_F)) ==
|
||||
isq::thermodynamic_temperature(5 * relative(si::degree_Celsius)));
|
||||
static_assert(isq::thermodynamic_temperature(9 * delta(deg_F)) ==
|
||||
isq::thermodynamic_temperature(5 * delta(si::degree_Celsius)));
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user