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
The behavior is to simply treat the error cases (overly large shifts and negative shifts) as resulting in zero, but it's not obvious this would happen. Mathematically, << s means $\times 2^s$, and the rest of the library treats overflow as wrapping. Why would a large shift then neither wrap the shift amount (via bitwise AND) nor wrap the resulting product of the multiplication? It just gives you zero on large shifts, which is what std::shl/Rust u32::unbounded_shl does. However, it's also not consistent about matching std::shl because negative shifts result in zero.
It's not clear from the documentation that overly large shifts and negative shifts are considered undefined behavior or are guaranteed to yield zero.
int128/include/boost/int128/detail/int128_imp.hpp
Lines 1349 to 1357 in f905e22
Some issues with this:
The behavior is to simply treat the error cases (overly large shifts and negative shifts) as resulting in zero, but it's not obvious this would happen. Mathematically,$\times 2^s$ , and the rest of the library treats overflow as wrapping. Why would a large shift then neither wrap the shift amount (via bitwise AND) nor wrap the resulting product of the multiplication? It just gives you zero on large shifts, which is what
<< smeansstd::shl/Rustu32::unbounded_shldoes. However, it's also not consistent about matchingstd::shlbecause negative shifts result in zero.It's not clear from the documentation that overly large shifts and negative shifts are considered undefined behavior or are guaranteed to yield zero.