xo-unit: promote to common repr in mixed-type operator* w/ quantity

Avoid truncating when, for example, multiplying
quantity<Unit, int> * double.

Add targeted unit test for this
This commit is contained in:
Roland Conybeare 2024-05-07 10:38:38 -04:00
commit df6cfbb25c
2 changed files with 22 additions and 1 deletions

View file

@ -106,7 +106,9 @@ namespace xo {
template <typename Dimensionless>
requires std::is_arithmetic_v<Dimensionless>
constexpr auto scale_by(Dimensionless x) const {
return quantity(x * this->scale_);
using r_repr_type = std::common_type_t<repr_type, Dimensionless>;
return quantity<s_unit, r_repr_type>(x * this->scale_);
}
// divide_by