@@ -188,7 +188,7 @@ mod wrapping;
188188// `Int` + `SignedInt` implemented for signed integers
189189macro_rules! int_impl {
190190 ( $SelfT: ty, $ActualT: ident, $UnsignedT: ty, $BITS: expr, $Min: expr, $Max: expr, $Feature: expr,
191- $EndFeature: expr) => {
191+ $EndFeature: expr, $rot : expr , $rot_op : expr , $rot_result : expr ) => {
192192 doc_comment! {
193193 concat!( "Returns the smallest value that can be represented by this integer type.
194194
@@ -334,55 +334,52 @@ $EndFeature, "
334334 }
335335 }
336336
337- /// Shifts the bits to the left by a specified amount, `n`,
338- /// wrapping the truncated bits to the end of the resulting integer.
339- ///
340- /// Please note this isn't the same operation as `<<`!
341- ///
342- /// # Examples
343- ///
344- /// Please note that this example is shared between integer types.
345- /// Which explains why `i64` is used here.
346- ///
347- /// Basic usage:
348- ///
349- /// ```
350- /// let n = 0x0123456789ABCDEFi64;
351- /// let m = -0x76543210FEDCBA99i64;
352- ///
353- /// assert_eq!(n.rotate_left(32), m);
354- /// ```
355- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
356- #[ inline]
357- pub fn rotate_left( self , n: u32 ) -> Self {
358- ( self as $UnsignedT) . rotate_left( n) as Self
359- }
337+ doc_comment! {
338+ concat!( "Shifts the bits to the left by a specified amount, `n`,
339+ wrapping the truncated bits to the end of the resulting integer.
360340
361- /// Shifts the bits to the right by a specified amount, `n`,
362- /// wrapping the truncated bits to the beginning of the resulting
363- /// integer.
364- ///
365- /// Please note this isn't the same operation as `>>`!
366- ///
367- /// # Examples
368- ///
369- /// Please note that this example is shared between integer types.
370- /// Which explains why `i64` is used here.
371- ///
372- /// Basic usage:
373- ///
374- /// ```
375- /// let n = 0x0123456789ABCDEFi64;
376- /// let m = -0xFEDCBA987654322i64;
377- ///
378- /// assert_eq!(n.rotate_right(4), m);
379- /// ```
380- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
381- #[ inline]
382- pub fn rotate_right( self , n: u32 ) -> Self {
383- ( self as $UnsignedT) . rotate_right( n) as Self
341+ Please note this isn't the same operation as `<<`!
342+
343+ # Examples
344+
345+ Basic usage:
346+
347+ ```
348+ let n = " , $rot_op, stringify!( $SelfT) , ";
349+ let m = " , $rot_result, ";
350+
351+ assert_eq!(n.rotate_left(" , $rot, "), m);
352+ ```" ) ,
353+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
354+ #[ inline]
355+ pub fn rotate_left( self , n: u32 ) -> Self {
356+ ( self as $UnsignedT) . rotate_left( n) as Self
357+ }
384358 }
385359
360+ doc_comment! {
361+ concat!( "Shifts the bits to the right by a specified amount, `n`,
362+ wrapping the truncated bits to the beginning of the resulting
363+ integer.
364+
365+ Please note this isn't the same operation as `>>`!
366+
367+ # Examples
368+
369+ Basic usage:
370+
371+ ```
372+ let n = " , $rot_result, stringify!( $SelfT) , ";
373+ let m = " , $rot_op, ";
374+
375+ assert_eq!(n.rotate_right(" , $rot, "), m);
376+ ```" ) ,
377+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
378+ #[ inline]
379+ pub fn rotate_right( self , n: u32 ) -> Self {
380+ ( self as $UnsignedT) . rotate_right( n) as Self
381+ }
382+ }
386383 /// Reverses the byte order of the integer.
387384 ///
388385 /// # Examples
@@ -1940,46 +1937,50 @@ $EndFeature, "
19401937
19411938#[ lang = "i8" ]
19421939impl i8 {
1943- int_impl ! { i8 , i8 , u8 , 8 , -128 , 127 , "" , "" }
1940+ int_impl ! { i8 , i8 , u8 , 8 , -128 , 127 , "" , "" , 2 , "-0x7e" , "0xa" }
19441941}
19451942
19461943#[ lang = "i16" ]
19471944impl i16 {
1948- int_impl ! { i16 , i16 , u16 , 16 , -32768 , 32767 , "" , "" }
1945+ int_impl ! { i16 , i16 , u16 , 16 , -32768 , 32767 , "" , "" , 4 , "-0x5ffd" , "0x3a" }
19491946}
19501947
19511948#[ lang = "i32" ]
19521949impl i32 {
1953- int_impl ! { i32 , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" }
1950+ int_impl ! { i32 , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" , 8 , "0x10000b3" , "0xb301" }
19541951}
19551952
19561953#[ lang = "i64" ]
19571954impl i64 {
1958- int_impl ! { i64 , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" }
1955+ int_impl ! { i64 , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" , 12 ,
1956+ "0xaa00000000006e1" , "0x6e10aa" }
19591957}
19601958
19611959#[ lang = "i128" ]
19621960impl i128 {
19631961 int_impl ! { i128 , i128 , u128 , 128 , -170141183460469231731687303715884105728 ,
1964- 170141183460469231731687303715884105727 , "" , "" }
1962+ 170141183460469231731687303715884105727 , "" , "" , 16 ,
1963+ "0x13f40000000000000000000000004f76" , "0x4f7613f4"
1964+ }
19651965}
19661966
19671967#[ cfg( target_pointer_width = "16" ) ]
19681968#[ lang = "isize" ]
19691969impl isize {
1970- int_impl ! { isize , i16 , u16 , 16 , -32768 , 32767 , "" , "" }
1970+ int_impl ! { isize , i16 , u16 , 16 , -32768 , 32767 , "" , "" , 4 , "-0x5ffd" , "0x3a" }
19711971}
19721972
19731973#[ cfg( target_pointer_width = "32" ) ]
19741974#[ lang = "isize" ]
19751975impl isize {
1976- int_impl ! { isize , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" }
1976+ int_impl ! { isize , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" , 8 , "0x10000b3" , "0xb301" }
19771977}
19781978
19791979#[ cfg( target_pointer_width = "64" ) ]
19801980#[ lang = "isize" ]
19811981impl isize {
1982- int_impl ! { isize , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" }
1982+ int_impl ! { isize , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" ,
1983+ 12 , "0xaa00000000006e1" , "0x6e10aa" }
19831984}
19841985
19851986// Emits the correct `cttz` call, depending on the size of the type.
@@ -1997,7 +1998,8 @@ macro_rules! uint_cttz_call {
19971998
19981999// `Int` + `UnsignedInt` implemented for unsigned integers
19992000macro_rules! uint_impl {
2000- ( $SelfT: ty, $ActualT: ty, $BITS: expr, $MaxV: expr, $Feature: expr, $EndFeature: expr) => {
2001+ ( $SelfT: ty, $ActualT: ty, $BITS: expr, $MaxV: expr, $Feature: expr, $EndFeature: expr,
2002+ $rot: expr, $rot_op: expr, $rot_result: expr) => {
20012003 doc_comment! {
20022004 concat!( "Returns the smallest value that can be represented by this integer type.
20032005
@@ -2138,57 +2140,55 @@ assert_eq!(n.trailing_zeros(), 3);", $EndFeature, "
21382140 }
21392141 }
21402142
2141- /// Shifts the bits to the left by a specified amount, `n`,
2142- /// wrapping the truncated bits to the end of the resulting integer.
2143- ///
2144- /// Please note this isn't the same operation as `<<`!
2145- ///
2146- /// # Examples
2147- ///
2148- /// Basic usage:
2149- ///
2150- /// Please note that this example is shared between integer types.
2151- /// Which explains why `u64` is used here.
2152- ///
2153- /// ```
2154- /// let n = 0x0123456789ABCDEFu64;
2155- /// let m = 0x3456789ABCDEF012u64;
2156- ///
2157- /// assert_eq!(n.rotate_left(12), m);
2158- /// ```
2159- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2160- #[ inline]
2161- pub fn rotate_left( self , n: u32 ) -> Self {
2162- // Protect against undefined behaviour for over-long bit shifts
2163- let n = n % $BITS;
2164- ( self << n) | ( self >> ( ( $BITS - n) % $BITS) )
2143+ doc_comment! {
2144+ concat!( "Shifts the bits to the left by a specified amount, `n`,
2145+ wrapping the truncated bits to the end of the resulting integer.
2146+
2147+ Please note this isn't the same operation as `<<`!
2148+
2149+ # Examples
2150+
2151+ Basic usage:
2152+
2153+ ```
2154+ let n = " , $rot_op, stringify!( $SelfT) , ";
2155+ let m = " , $rot_result, ";
2156+
2157+ assert_eq!(n.rotate_left(" , $rot, "), m);
2158+ ```" ) ,
2159+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2160+ #[ inline]
2161+ pub fn rotate_left( self , n: u32 ) -> Self {
2162+ // Protect against undefined behaviour for over-long bit shifts
2163+ let n = n % $BITS;
2164+ ( self << n) | ( self >> ( ( $BITS - n) % $BITS) )
2165+ }
21652166 }
21662167
2167- /// Shifts the bits to the right by a specified amount, `n`,
2168- /// wrapping the truncated bits to the beginning of the resulting
2169- /// integer.
2170- ///
2171- /// Please note this isn't the same operation as `>>`!
2172- ///
2173- /// # Examples
2174- ///
2175- /// Basic usage:
2176- ///
2177- /// Please note that this example is shared between integer types.
2178- /// Which explains why `u64` is used here.
2179- ///
2180- /// ```
2181- /// let n = 0x0123456789ABCDEFu64;
2182- /// let m = 0xDEF0123456789ABCu64;
2183- ///
2184- /// assert_eq!(n.rotate_right(12), m);
2185- /// ```
2186- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2187- #[ inline]
2188- pub fn rotate_right( self , n: u32 ) -> Self {
2189- // Protect against undefined behaviour for over-long bit shifts
2190- let n = n % $BITS;
2191- ( self >> n) | ( self << ( ( $BITS - n) % $BITS) )
2168+ doc_comment! {
2169+ concat!( "Shifts the bits to the right by a specified amount, `n`,
2170+ wrapping the truncated bits to the beginning of the resulting
2171+ integer.
2172+
2173+ Please note this isn't the same operation as `>>`!
2174+
2175+ # Examples
2176+
2177+ Basic usage:
2178+
2179+ ```
2180+ let n = " , $rot_result, stringify!( $SelfT) , ";
2181+ let m = " , $rot_op, ";
2182+
2183+ assert_eq!(n.rotate_right(" , $rot, "), m);
2184+ ```" ) ,
2185+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2186+ #[ inline]
2187+ pub fn rotate_right( self , n: u32 ) -> Self {
2188+ // Protect against undefined behaviour for over-long bit shifts
2189+ let n = n % $BITS;
2190+ ( self >> n) | ( self << ( ( $BITS - n) % $BITS) )
2191+ }
21922192 }
21932193
21942194 /// Reverses the byte order of the integer.
@@ -3549,7 +3549,7 @@ $EndFeature, "
35493549
35503550#[ lang = "u8" ]
35513551impl u8 {
3552- uint_impl ! { u8 , u8 , 8 , 255 , "" , "" }
3552+ uint_impl ! { u8 , u8 , 8 , 255 , "" , "" , 2 , "0x82" , "0xa" }
35533553
35543554
35553555 /// Checks if the value is within the ASCII range.
@@ -4095,39 +4095,41 @@ impl u8 {
40954095
40964096#[ lang = "u16" ]
40974097impl u16 {
4098- uint_impl ! { u16 , u16 , 16 , 65535 , "" , "" }
4098+ uint_impl ! { u16 , u16 , 16 , 65535 , "" , "" , 4 , "0xa003" , "0x3a" }
40994099}
41004100
41014101#[ lang = "u32" ]
41024102impl u32 {
4103- uint_impl ! { u32 , u32 , 32 , 4294967295 , "" , "" }
4103+ uint_impl ! { u32 , u32 , 32 , 4294967295 , "" , "" , 8 , "0x10000b3" , "0xb301" }
41044104}
41054105
41064106#[ lang = "u64" ]
41074107impl u64 {
4108- uint_impl ! { u64 , u64 , 64 , 18446744073709551615 , "" , "" }
4108+ uint_impl ! { u64 , u64 , 64 , 18446744073709551615 , "" , "" , 12 , "0xaa00000000006e1" , "0x6e10aa" }
41094109}
41104110
41114111#[ lang = "u128" ]
41124112impl u128 {
4113- uint_impl ! { u128 , u128 , 128 , 340282366920938463463374607431768211455 , "" , "" }
4113+ uint_impl ! { u128 , u128 , 128 , 340282366920938463463374607431768211455 , "" , "" , 16 ,
4114+ "0x13f40000000000000000000000004f76" , "0x4f7613f4" }
41144115}
41154116
41164117#[ cfg( target_pointer_width = "16" ) ]
41174118#[ lang = "usize" ]
41184119impl usize {
4119- uint_impl ! { usize , u16 , 16 , 65536 , "" , "" }
4120+ uint_impl ! { usize , u16 , 16 , 65536 , "" , "" , 4 , "0xa003" , "0x3a" }
41204121}
41214122#[ cfg( target_pointer_width = "32" ) ]
41224123#[ lang = "usize" ]
41234124impl usize {
4124- uint_impl ! { usize , u32 , 32 , 4294967295 , "" , "" }
4125+ uint_impl ! { usize , u32 , 32 , 4294967295 , "" , "" , 8 , "0x10000b3" , "0xb301" }
41254126}
41264127
41274128#[ cfg( target_pointer_width = "64" ) ]
41284129#[ lang = "usize" ]
41294130impl usize {
4130- uint_impl ! { usize , u64 , 64 , 18446744073709551615 , "" , "" }
4131+ uint_impl ! { usize , u64 , 64 , 18446744073709551615 , "" , "" , 12 , "0xaa00000000006e1" ,
4132+ "0x6e10aa" }
41314133}
41324134
41334135/// A classification of floating point numbers.
0 commit comments