Replies: 3 comments 7 replies
-
Hi, thanks for trying out the library. It seems that we have an interesting use case here. It is even not about the cyclic problem you refer to above. The problem is bigger. Volume divided by the area is just a length so you try to overwrite an existing base dimension. As a consequence So let's try to cheat a bit here 😉: using area_in_m2 = area<square_metre, unsigned int>;
using volume_in_ml = units::isq::si::volume<millilitre, unsigned int>;
using dim_volume_per_area = dim_length;
struct decilitre_per_m2 : units::alias_unit<micrometre, "dl/m2", units::no_prefix> {};
using volume_per_area = units::quantity<dim_volume_per_area, decilitre_per_m2, unsigned int>;
volume_in_ml volume(10);
area_in_m2 area(2);
volume_per_area vpa = volume / area; https://godbolt.org/z/PoKzevfG1 I am not happy that I had to hardcode Please let me know how this solution addresses your concerns? |
Beta Was this translation helpful? Give feedback.
-
Thanks for suggestions. Volume / area is indeed length! :) In strictly technical point of view. In real world, I have some dosage of some chemistry in agriculture and real world unit is dl/m2, so I have to conform to reality. There's problem with scaling in the suggested code:
decilitre_per_m2 is not micrometre. micrometre is 1 millilitre / 1 square metre and I need decilitres. On the end of the pipe I have some embedded device that does fixed point calculations, with dl/m2. Of course I can scale on output, but wanted to offload all this burden to the units library, that's what it's for. Isn't it?
Is there a better way to define this with alias_unit? Without my invented prefix? All is good, more or less. It works as expected for this quantity, so thanks for the suggestion!
I have to add explicit cast:
Is it expected behaviour? I also have such calculation:
And last assignment also doesn't compile. It requires explicit cast:
Is it expected behaviour? With all these casts, code becomes somewhat ugly... |
Beta Was this translation helpful? Give feedback.
-
Thanks for your thorough explanations! Now back to coding, I've chosen your library for my code and I hope to ask fewer and fewer questions (more knowledge on my side). |
Beta Was this translation helpful? Give feedback.
-
Hi,
Thank your for this great library. I'm using it successfully in data acquisition system. So far, I was using it for base units from SI system and things are straightforward.
Going further, I got to the point where I need to make some calculations with derived units.
I have area in square metres and volume in milliliters:
Now I'm trying to derive new scaled unit, and please excuse me, but some confusion arises - I need new unit: decilitre per square meter.
According to examples from manual, here comes derived unit:
But it needs it's own dimension (dim_volume_per_area here), and this I'm trying to declare as:
This is cyclic dependency (unit requires dimension, dimension requires unit) that probably is my mistake, but I'm stuck for now and can't figure this out. Please advise...
Furthermore, I expect such example calculation to be correct (converting millilitres to decilitres in between):
Should I expect implicit casts to just happen, or do I need explicit cast to volume_per_area type?
Beta Was this translation helpful? Give feedback.
All reactions