G'day folks!
I'm looking for simple, straightforward, traditional bitshift behavior and can't find it in the Rust docs.
I assume that because, 1u32 << 32
overflows, it panics because overflow is defined as undefined, or something.
But what if I don't want it to panic? What if I want 1u32 << 32 == 0
?
So I found wrapping_shl
and it's unstable companion overflowing_shl()
, but I find the behavior of those bizarre. Maybe I just haven't come across the use case where the shift should keep wrapping around. It doesn't seem generally useful for std::u32::MAX << 32 == std::u32::MAX
...
Is there any way to do a simple overflowing shift that doesn't wrap and doesn't panic without an excess of anding and conditional instructions when one basic shl
instruction will do? Or do I basically have to use a condition to return 0
when the shift would overflow?
Thanks for any advice!