From c0248c0839cfdf5b7030f4191ea7aed0981b9e4e Mon Sep 17 00:00:00 2001 From: Samuel Neves Date: Wed, 2 Jul 2014 04:58:23 +0100 Subject: Fix rotate_{left, right} for multiple of bitsize rotation amounts Add additional rotation tests --- src/libcore/num/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libcore/num') diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index b32e4167da1..1fae362471d 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -586,14 +586,14 @@ macro_rules! int_impl { fn rotate_left(self, n: uint) -> $T { // Protect against undefined behaviour for over-long bit shifts let n = n % $BITS; - (self << n) | (self >> ($BITS - n)) + (self << n) | (self >> (($BITS - n) % $BITS)) } #[inline] fn rotate_right(self, n: uint) -> $T { // Protect against undefined behaviour for over-long bit shifts let n = n % $BITS; - (self >> n) | (self << ($BITS - n)) + (self >> n) | (self << (($BITS - n) % $BITS)) } #[inline] -- cgit 1.4.1-3-g733a5