You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when x is smaller than int, e.g., short. to_unsigned(x) returns a value of type unsigned short. using it as an operand of an arithmetic operation ~x, it first gets promoted to int, then the operation gets applied, returning another int, which causes the call to std::popcount to fail since it's a signed integer type.
to fix this we could write it as
auto u = to_unsigned(x);
usingunsigned = decltype(u);
return std::popcount(static_cast<unsigned>(~u));
The text was updated successfully, but these errors were encountered:
I think the easiest fix is gonna be std::popcount(to_unsigned(~to_unsigned(x)). Casting to unsigned isn't correct because it won't work right for 64-bit arguments. Feel free to file a pull request here.
it currently returns
when
x
is smaller thanint
, e.g.,short
.to_unsigned(x)
returns a value of typeunsigned short
. using it as an operand of an arithmetic operation~x
, it first gets promoted toint
, then the operation gets applied, returning anotherint
, which causes the call tostd::popcount
to fail since it's a signed integer type.to fix this we could write it as
The text was updated successfully, but these errors were encountered: