Closed crisluengo closed 1 month ago
Also, I would have put the templated functions in a namespace, but util
is a struct, not a namespace, and all of this is already in the detail
namespace, so I just made the function name a bit longer... :)
What do you think about #17? This is yuor commit plus some tweaks that allow us to go back to the original naming.
In your test code I changed the signed integers to unsigned ones, and then everything works again.
I guess it's not meant to be called by the user? If it's only an internal function, then this is fine. I had made the stub functions so that the input is automatically cast to unsigned int, which is more user-friendly.
It's no problem to suport signed integers as well, but then we'd have (strictly speaking) to check for negative input to be safe, and I thought we could perhaps avoid this kind of silliness already by using an appropriate input type.
In your example, if you do
int good_size = good_size_cmplx((1u<<31)+5)
you'll end up with a nasty surprise as well, I think, so it doesn't save you from being careful with data types.
As long as the function is called with something like vector.size()
as input, none of this really matters. I don't know how this function is used, but I would expect it's never with some hard-coded constant.
But be aware that, on a 64-bit system, good_size_cmplx(4294967295u)
throws (because the result doesn't fit in an unsigned int), whereas good_size_cmplx(4294967295ull)
doesn't.
Sorry for taking so long with this ...
I think your approch is the most reasonable after all; I only made a few pedantic changes (instead of comparing the size of the type to 4, I check whether it is smaller than uint64?t
).
I've tried to push to your branch directly as suggested by the PR, but I couldn't figure out how this works, so I updated #17 accordingly.
No worries. I'll just close this PR, you commit the fix in #17 however you think is best.
By the way, thanks for all the work you put into this library, it's fantastic!
This should fix issue #15 in the manner discussed there.
I tried to follow the existing code style, but feel free to reformat or edit in any way.
In my own version of these functions, I combined the code for
_cmplx
and_real
by making the maximum factor a template parameter as well. That reduces code duplication a bit. I'm happy to do that here too if you like.This was my test program, for posterity: