Replies: 1 comment 10 replies
-
|
@Jashweii, thanks a lot for your feedback. This is very interesting, and I admit that even though I thought about it and thought if that would be possible, I never tried to code it.
This is not entirely true. In our docs we have an entire chapter on Dimensionless Quantities. We also have a workshop on Strongly-Typed Counts.
Index is technically a quantity point. So you may define "0 vs 1 indexing" with them and relative origins: https://godbolt.org/z/x4r1xTE5E. I know it is a bit hacky and the syntax may not be perfect, but it works. It can be extended to other cases as well, easily.
As long as indexes, offsets, and strides are quantities, I would argue that masks are not. You can't add numerically two masks or divide it by a scalar. This is why, even though I could provide some hacky solution even today, it is probably best not to use this library. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm posting this in view of having read the slides & skimmed through the paper for the proposed standardised Quantity & Unit library, I haven't personally used the library though I have wanted something similar in the past.
I think the library is very useful but is almost exclusively geared towards SI-style scientific and engineering "end-"domains of programs, and extensibility in terms of new units. I think programming itself has its own types of quantity, unit and conversion that have very similar problems that don't or almost fit the mould (e.g. new operations). I wanted to bring some basic examples of the problem space up, not in the hope of them getting solved any time soon, but in case they raise any questions for the design or forwards compatibility (or a sort of sideways extensibility). For a bikeshed example, the namespace if there was a different system of non-SI units.
Index related. Many of these relate to non-integral length also (apart from endianness and iterators).
0 vs 1 indexing (akin to affine space origin)
Index in bits, bytes, megabytes, mebibytes, elements with size S and [S inclusive/exclusive] stride U...
Element type could produce incomparable quantities.
Index vs offset vs size vs stride vs alignment (related quantities of the same kind that sometimes are the same)
Functions taking many integral parameters (easily mixed up)
Indices into different things (quantities of the same kind)
Inclusive or exclusive indices [perhaps better as an orthogonal interval library? I would imagine overlap with quantities though]
Modular: negative (-1 as last) and circular (wrap around) indices.
This could also be useful for angles (only sometimes) and perhaps length/distance (e.g. around a disk).
The paper does briefly reference another paper on this, but without the focus on units.
I'm not sure whether it would be a better idea to do it on the quantity or the representation, on the quantity could lead to improved accuracy when other types are involved.
(But probably wouldn't in general without over-complicating things.)
Perhaps more importantly though the bounds are tied to the unit.
If an angle is in [-π,π] radians and gets converted to half turns, it should be in [-1, 1] half turns or [-π, π] radians (bounded by a comparable unit), not [-π, π] half turns (problem delegated to representation).
This is perhaps a more general problem than e.g. knowing your value is going to be non-negative (but perhaps it then relates to affine spaces?).
I would imagine the ideal solution would look something like
quantity[_point]<periodic<Q, start, end>, T>orperiodic<quantity_point<Q, T>, start, end>. E.g.quantity<periodic<angle, -π, π>, double>.[If one of these worked, you could also imagine a bounded or saturated version.]
Endianness of network bytes (as a unit)
Iterators & pointers as positions, indices and difference type as deltas
Including e.g. adding raw byte offsets to typed pointers.
Masks (very common in conjunction with enums)
It's not uncommon to end up working with all three, and having to convert between and avoid confusing them despite the same type, which is error prone and tedious for all the same reasons.
Beta Was this translation helpful? Give feedback.
All reactions