@@ -188,7 +188,7 @@ mod wrapping;
188
188
// `Int` + `SignedInt` implemented for signed integers
189
189
macro_rules! int_impl {
190
190
( $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 ) => {
192
192
doc_comment! {
193
193
concat!( "Returns the smallest value that can be represented by this integer type.
194
194
@@ -334,55 +334,52 @@ $EndFeature, "
334
334
}
335
335
}
336
336
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.
360
340
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
+ }
384
358
}
385
359
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
+ }
386
383
/// Reverses the byte order of the integer.
387
384
///
388
385
/// # Examples
@@ -1940,46 +1937,50 @@ $EndFeature, "
1940
1937
1941
1938
#[ lang = "i8" ]
1942
1939
impl i8 {
1943
- int_impl ! { i8 , i8 , u8 , 8 , -128 , 127 , "" , "" }
1940
+ int_impl ! { i8 , i8 , u8 , 8 , -128 , 127 , "" , "" , 2 , "-0x7e" , "0xa" }
1944
1941
}
1945
1942
1946
1943
#[ lang = "i16" ]
1947
1944
impl i16 {
1948
- int_impl ! { i16 , i16 , u16 , 16 , -32768 , 32767 , "" , "" }
1945
+ int_impl ! { i16 , i16 , u16 , 16 , -32768 , 32767 , "" , "" , 4 , "-0x5ffd" , "0x3a" }
1949
1946
}
1950
1947
1951
1948
#[ lang = "i32" ]
1952
1949
impl i32 {
1953
- int_impl ! { i32 , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" }
1950
+ int_impl ! { i32 , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" , 8 , "0x10000b3" , "0xb301" }
1954
1951
}
1955
1952
1956
1953
#[ lang = "i64" ]
1957
1954
impl i64 {
1958
- int_impl ! { i64 , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" }
1955
+ int_impl ! { i64 , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" , 12 ,
1956
+ "0xaa00000000006e1" , "0x6e10aa" }
1959
1957
}
1960
1958
1961
1959
#[ lang = "i128" ]
1962
1960
impl i128 {
1963
1961
int_impl ! { i128 , i128 , u128 , 128 , -170141183460469231731687303715884105728 ,
1964
- 170141183460469231731687303715884105727 , "" , "" }
1962
+ 170141183460469231731687303715884105727 , "" , "" , 16 ,
1963
+ "0x13f40000000000000000000000004f76" , "0x4f7613f4"
1964
+ }
1965
1965
}
1966
1966
1967
1967
#[ cfg( target_pointer_width = "16" ) ]
1968
1968
#[ lang = "isize" ]
1969
1969
impl isize {
1970
- int_impl ! { isize , i16 , u16 , 16 , -32768 , 32767 , "" , "" }
1970
+ int_impl ! { isize , i16 , u16 , 16 , -32768 , 32767 , "" , "" , 4 , "-0x5ffd" , "0x3a" }
1971
1971
}
1972
1972
1973
1973
#[ cfg( target_pointer_width = "32" ) ]
1974
1974
#[ lang = "isize" ]
1975
1975
impl isize {
1976
- int_impl ! { isize , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" }
1976
+ int_impl ! { isize , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" , 8 , "0x10000b3" , "0xb301" }
1977
1977
}
1978
1978
1979
1979
#[ cfg( target_pointer_width = "64" ) ]
1980
1980
#[ lang = "isize" ]
1981
1981
impl isize {
1982
- int_impl ! { isize , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" }
1982
+ int_impl ! { isize , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" ,
1983
+ 12 , "0xaa00000000006e1" , "0x6e10aa" }
1983
1984
}
1984
1985
1985
1986
// Emits the correct `cttz` call, depending on the size of the type.
@@ -1997,7 +1998,8 @@ macro_rules! uint_cttz_call {
1997
1998
1998
1999
// `Int` + `UnsignedInt` implemented for unsigned integers
1999
2000
macro_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) => {
2001
2003
doc_comment! {
2002
2004
concat!( "Returns the smallest value that can be represented by this integer type.
2003
2005
@@ -2138,57 +2140,55 @@ assert_eq!(n.trailing_zeros(), 3);", $EndFeature, "
2138
2140
}
2139
2141
}
2140
2142
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
+ }
2165
2166
}
2166
2167
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
+ }
2192
2192
}
2193
2193
2194
2194
/// Reverses the byte order of the integer.
@@ -3549,7 +3549,7 @@ $EndFeature, "
3549
3549
3550
3550
#[ lang = "u8" ]
3551
3551
impl u8 {
3552
- uint_impl ! { u8 , u8 , 8 , 255 , "" , "" }
3552
+ uint_impl ! { u8 , u8 , 8 , 255 , "" , "" , 2 , "0x82" , "0xa" }
3553
3553
3554
3554
3555
3555
/// Checks if the value is within the ASCII range.
@@ -4095,39 +4095,41 @@ impl u8 {
4095
4095
4096
4096
#[ lang = "u16" ]
4097
4097
impl u16 {
4098
- uint_impl ! { u16 , u16 , 16 , 65535 , "" , "" }
4098
+ uint_impl ! { u16 , u16 , 16 , 65535 , "" , "" , 4 , "0xa003" , "0x3a" }
4099
4099
}
4100
4100
4101
4101
#[ lang = "u32" ]
4102
4102
impl u32 {
4103
- uint_impl ! { u32 , u32 , 32 , 4294967295 , "" , "" }
4103
+ uint_impl ! { u32 , u32 , 32 , 4294967295 , "" , "" , 8 , "0x10000b3" , "0xb301" }
4104
4104
}
4105
4105
4106
4106
#[ lang = "u64" ]
4107
4107
impl u64 {
4108
- uint_impl ! { u64 , u64 , 64 , 18446744073709551615 , "" , "" }
4108
+ uint_impl ! { u64 , u64 , 64 , 18446744073709551615 , "" , "" , 12 , "0xaa00000000006e1" , "0x6e10aa" }
4109
4109
}
4110
4110
4111
4111
#[ lang = "u128" ]
4112
4112
impl u128 {
4113
- uint_impl ! { u128 , u128 , 128 , 340282366920938463463374607431768211455 , "" , "" }
4113
+ uint_impl ! { u128 , u128 , 128 , 340282366920938463463374607431768211455 , "" , "" , 16 ,
4114
+ "0x13f40000000000000000000000004f76" , "0x4f7613f4" }
4114
4115
}
4115
4116
4116
4117
#[ cfg( target_pointer_width = "16" ) ]
4117
4118
#[ lang = "usize" ]
4118
4119
impl usize {
4119
- uint_impl ! { usize , u16 , 16 , 65536 , "" , "" }
4120
+ uint_impl ! { usize , u16 , 16 , 65536 , "" , "" , 4 , "0xa003" , "0x3a" }
4120
4121
}
4121
4122
#[ cfg( target_pointer_width = "32" ) ]
4122
4123
#[ lang = "usize" ]
4123
4124
impl usize {
4124
- uint_impl ! { usize , u32 , 32 , 4294967295 , "" , "" }
4125
+ uint_impl ! { usize , u32 , 32 , 4294967295 , "" , "" , 8 , "0x10000b3" , "0xb301" }
4125
4126
}
4126
4127
4127
4128
#[ cfg( target_pointer_width = "64" ) ]
4128
4129
#[ lang = "usize" ]
4129
4130
impl usize {
4130
- uint_impl ! { usize , u64 , 64 , 18446744073709551615 , "" , "" }
4131
+ uint_impl ! { usize , u64 , 64 , 18446744073709551615 , "" , "" , 12 , "0xaa00000000006e1" ,
4132
+ "0x6e10aa" }
4131
4133
}
4132
4134
4133
4135
/// A classification of floating point numbers.
0 commit comments