nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
947 stars 135 forks source link

Questions about change the underlying type #225

Open jpires opened 5 years ago

jpires commented 5 years ago

Hello, I have a few question to you, and I hope this is the correct way of doing them. Please tell me if that is not the case, and what is the correct way.

So, I am starting the development of a new piece of software that needs to handle voltages, current, power and energy and this library would remove a lot of error that were made in the pass, as it would ensure that we don't do any wrong operations. Thanks for all the work :)

However, the hardware where we are gonna run this, it doesn't have support for floating point types.

After looking into the documentation I saw that it is possible to change the underlying type. Try to change it int using this code definition.

using volt_t = units::unit_t<units::voltage::volt, int, units::linear_scale>;
using millivolt_t = units::unit_t<units::voltage::millivolt, int, units::linear_scale>;

My issue is that when a conversion leads to data loss, e.g. millivolt_t to volt_t, there is no warning. Is it possible to enable this type of warnings for v2.3.1?

I tried to do the same thing on the branch V3.x and there it fails to compile when doing that conversion. What is the status of V3.x branch? Anymore major refactor planed?

Thanks