c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Move safe_mul_div macro and make it generic on integer types

Open cheese3660 opened this issue 1 year ago • 4 comments

This moves the recently added safe_mul_div macro in std::time::os (win32) to std::math and then should make it generic for integer types.

cheese3660 avatar Aug 08 '24 21:08 cheese3660

Add a unit test and rename it mul_div

lerno avatar Aug 09 '24 07:08 lerno

Or possibly int_mult_div. One can also consider adding it as a macro method on all numbers, so you can do foo.mult_div(a, b) on all integers and integer vectors.

lerno avatar Aug 09 '24 07:08 lerno

I think I'll see about doing the latter option there

cheese3660 avatar Aug 09 '24 11:08 cheese3660

should the integer vector variants apply it as a scalar over all members, or do it with another vector of numbers, or be able to do both?

Edit: decided to do both

cheese3660 avatar Aug 09 '24 11:08 cheese3660

Alright, with some testing, I have found that these functions are only guaranteed to work correctly for any number even if N*mul results in a larger bitwidth than the result can hold if mul*div does not result in a number with a larger bitwidth than the type the operation is being done on, or the operation is being done on a scalar type that would promote to int. But the changes I just pushed should implement what you asked

cheese3660 avatar Aug 09 '24 15:08 cheese3660

How did my copying of the sema_expr fix get into there, I specifically intended not to put it into the commit history.

cheese3660 avatar Aug 09 '24 15:08 cheese3660

Thank you!

lerno avatar Aug 09 '24 20:08 lerno

I think it was squashed as there was the same fix in master?

lerno avatar Aug 09 '24 21:08 lerno