mpusz / wg21-papers

ISO C++ Committee papers by Mateusz Pusz
https://mpusz.github.io/wg21-papers
4 stars 7 forks source link

`std::quantity` as a numeric type #20

Open mpusz opened 1 year ago

mpusz commented 1 year ago
JohelEGP commented 11 months ago

I understand the structure.

Please, clarify the intent. Is it also a wording paper?

For the non-wording portions, I think we'll be able to reuse a lot of mp-units' documentation, which is in pretty good shape. How do you think they'll differ? Here's what I'm thinking:

mpusz commented 11 months ago

Is it also a wording paper?

No. It is meant to solve all of the math-related issues and concerns before we provide the first paper for LEWG with interfaces and, eventually, wording in later revisions.

I think we'll be able to reuse a lot of mp-units' documentation,

That's the point :-) I was writing the documentation with that in mind. If not copy-and-paste, documentation still highlights most things we need to describe there. The audience is different, so pure copy-paste may not be enough,

Here's what I'm thinking:

Agree.

mpusz commented 11 months ago

We also need to describe that as long as number * unit to get the value of a quantity is defined in the SI Brochure, quantity */ unit and number / unit is added by us for the engineering convenience.

JohelEGP commented 11 months ago

That's just math. Let $quantity = number unit$, $quantity / unit = number unit / unit = number$. We had removed that possibility in code because [see https://github.com/mpusz/mp-units/pull/262#issuecomment-802493851].

mpusz commented 11 months ago
  1. Potentially more expensive when Rep is expensive to copy/move (quantity with a numeric value copied/moved many times before the final unit is obtained)
  2. Multiplication is commutative so should m * 42 be a thing? This seems wrong to me.
  3. Should 42 / s construct a quantity? If so, how to define a quantity<1 / s> or define hertz with:
inline constexpr struct hertz : named_unit<"Hz", 1 / second, kind_of<isq::frequency>> {} hertz;

It seems that only multiplication after a number has a sense, or we would have to heavily complicate the notation of inverses for units, dimensions, and quantity_specs (i.e. using std::integral_constant).