safe-arithmetic icon indicating copy to clipboard operation
safe-arithmetic copied to clipboard

🧑‍🔬 Make sure safe arithmetic works with a dimensional analysis library (like mpusz/units)

Open lukevalenty opened this issue 3 years ago • 2 comments

lukevalenty avatar Nov 30 '22 22:11 lukevalenty

Some notes on how this might work.

safe::var<int, ival<0, 1023>, km / h> current_speed = 100_s32 * km / h;

constexpr auto speed_limit = 100_s32 * km / h;
units::some_type<safe::var<int, ival<0, 1023>>> current_speed = 100_s32 * km / h;

safe::var<unit::some_type<int, km / h>, ival<0, 1023>> current_speed = 100_s32 * km / h;
units::some_type<safe::var<int, ival<100, 100>>>

lukevalenty avatar Nov 30 '22 22:11 lukevalenty

another variation of the top that does a better job satisfying the DRY principle:

auto current_speed = s32_ival<0, 1023>{100_s32} * km / h;

lukevalenty avatar Dec 01 '22 20:12 lukevalenty