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:
parent
3e86011f51
commit
df6cfbb25c
2 changed files with 22 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue