@@ -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
@@ -2012,46 +2009,50 @@ $EndFeature, "
2012
2009
2013
2010
#[ lang = "i8" ]
2014
2011
impl i8 {
2015
- int_impl ! { i8 , i8 , u8 , 8 , -128 , 127 , "" , "" }
2012
+ int_impl ! { i8 , i8 , u8 , 8 , -128 , 127 , "" , "" , 2 , "-0x7e" , "0xa" }
2016
2013
}
2017
2014
2018
2015
#[ lang = "i16" ]
2019
2016
impl i16 {
2020
- int_impl ! { i16 , i16 , u16 , 16 , -32768 , 32767 , "" , "" }
2017
+ int_impl ! { i16 , i16 , u16 , 16 , -32768 , 32767 , "" , "" , 4 , "-0x5ffd" , "0x3a" }
2021
2018
}
2022
2019
2023
2020
#[ lang = "i32" ]
2024
2021
impl i32 {
2025
- int_impl ! { i32 , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" }
2022
+ int_impl ! { i32 , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" , 8 , "0x10000b3" , "0xb301" }
2026
2023
}
2027
2024
2028
2025
#[ lang = "i64" ]
2029
2026
impl i64 {
2030
- int_impl ! { i64 , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" }
2027
+ int_impl ! { i64 , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" , 12 ,
2028
+ "0xaa00000000006e1" , "0x6e10aa" }
2031
2029
}
2032
2030
2033
2031
#[ lang = "i128" ]
2034
2032
impl i128 {
2035
2033
int_impl ! { i128 , i128 , u128 , 128 , -170141183460469231731687303715884105728 ,
2036
- 170141183460469231731687303715884105727 , "" , "" }
2034
+ 170141183460469231731687303715884105727 , "" , "" , 16 ,
2035
+ "0x13f40000000000000000000000004f76" , "0x4f7613f4"
2036
+ }
2037
2037
}
2038
2038
2039
2039
#[ cfg( target_pointer_width = "16" ) ]
2040
2040
#[ lang = "isize" ]
2041
2041
impl isize {
2042
- int_impl ! { isize , i16 , u16 , 16 , -32768 , 32767 , "" , "" }
2042
+ int_impl ! { isize , i16 , u16 , 16 , -32768 , 32767 , "" , "" , 4 , "-0x5ffd" , "0x3a" }
2043
2043
}
2044
2044
2045
2045
#[ cfg( target_pointer_width = "32" ) ]
2046
2046
#[ lang = "isize" ]
2047
2047
impl isize {
2048
- int_impl ! { isize , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" }
2048
+ int_impl ! { isize , i32 , u32 , 32 , -2147483648 , 2147483647 , "" , "" , 8 , "0x10000b3" , "0xb301" }
2049
2049
}
2050
2050
2051
2051
#[ cfg( target_pointer_width = "64" ) ]
2052
2052
#[ lang = "isize" ]
2053
2053
impl isize {
2054
- int_impl ! { isize , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" }
2054
+ int_impl ! { isize , i64 , u64 , 64 , -9223372036854775808 , 9223372036854775807 , "" , "" ,
2055
+ 12 , "0xaa00000000006e1" , "0x6e10aa" }
2055
2056
}
2056
2057
2057
2058
// Emits the correct `cttz` call, depending on the size of the type.
@@ -2069,7 +2070,8 @@ macro_rules! uint_cttz_call {
2069
2070
2070
2071
// `Int` + `UnsignedInt` implemented for unsigned integers
2071
2072
macro_rules! uint_impl {
2072
- ( $SelfT: ty, $ActualT: ty, $BITS: expr, $MaxV: expr, $Feature: expr, $EndFeature: expr) => {
2073
+ ( $SelfT: ty, $ActualT: ty, $BITS: expr, $MaxV: expr, $Feature: expr, $EndFeature: expr,
2074
+ $rot: expr, $rot_op: expr, $rot_result: expr) => {
2073
2075
doc_comment! {
2074
2076
concat!( "Returns the smallest value that can be represented by this integer type.
2075
2077
@@ -2210,57 +2212,55 @@ assert_eq!(n.trailing_zeros(), 3);", $EndFeature, "
2210
2212
}
2211
2213
}
2212
2214
2213
- /// Shifts the bits to the left by a specified amount, `n`,
2214
- /// wrapping the truncated bits to the end of the resulting integer.
2215
- ///
2216
- /// Please note this isn't the same operation as `<<`!
2217
- ///
2218
- /// # Examples
2219
- ///
2220
- /// Basic usage:
2221
- ///
2222
- /// Please note that this example is shared between integer types.
2223
- /// Which explains why `u64` is used here.
2224
- ///
2225
- /// ```
2226
- /// let n = 0x0123456789ABCDEFu64;
2227
- /// let m = 0x3456789ABCDEF012u64;
2228
- ///
2229
- /// assert_eq!(n.rotate_left(12), m);
2230
- /// ```
2231
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2232
- #[ inline]
2233
- pub fn rotate_left( self , n: u32 ) -> Self {
2234
- // Protect against undefined behaviour for over-long bit shifts
2235
- let n = n % $BITS;
2236
- ( self << n) | ( self >> ( ( $BITS - n) % $BITS) )
2215
+ doc_comment! {
2216
+ concat!( "Shifts the bits to the left by a specified amount, `n`,
2217
+ wrapping the truncated bits to the end of the resulting integer.
2218
+
2219
+ Please note this isn't the same operation as `<<`!
2220
+
2221
+ # Examples
2222
+
2223
+ Basic usage:
2224
+
2225
+ ```
2226
+ let n = " , $rot_op, stringify!( $SelfT) , ";
2227
+ let m = " , $rot_result, ";
2228
+
2229
+ assert_eq!(n.rotate_left(" , $rot, "), m);
2230
+ ```" ) ,
2231
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2232
+ #[ inline]
2233
+ pub fn rotate_left( self , n: u32 ) -> Self {
2234
+ // Protect against undefined behaviour for over-long bit shifts
2235
+ let n = n % $BITS;
2236
+ ( self << n) | ( self >> ( ( $BITS - n) % $BITS) )
2237
+ }
2237
2238
}
2238
2239
2239
- /// Shifts the bits to the right by a specified amount, `n`,
2240
- /// wrapping the truncated bits to the beginning of the resulting
2241
- /// integer.
2242
- ///
2243
- /// Please note this isn't the same operation as `>>`!
2244
- ///
2245
- /// # Examples
2246
- ///
2247
- /// Basic usage:
2248
- ///
2249
- /// Please note that this example is shared between integer types.
2250
- /// Which explains why `u64` is used here.
2251
- ///
2252
- /// ```
2253
- /// let n = 0x0123456789ABCDEFu64;
2254
- /// let m = 0xDEF0123456789ABCu64;
2255
- ///
2256
- /// assert_eq!(n.rotate_right(12), m);
2257
- /// ```
2258
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2259
- #[ inline]
2260
- pub fn rotate_right( self , n: u32 ) -> Self {
2261
- // Protect against undefined behaviour for over-long bit shifts
2262
- let n = n % $BITS;
2263
- ( self >> n) | ( self << ( ( $BITS - n) % $BITS) )
2240
+ doc_comment! {
2241
+ concat!( "Shifts the bits to the right by a specified amount, `n`,
2242
+ wrapping the truncated bits to the beginning of the resulting
2243
+ integer.
2244
+
2245
+ Please note this isn't the same operation as `>>`!
2246
+
2247
+ # Examples
2248
+
2249
+ Basic usage:
2250
+
2251
+ ```
2252
+ let n = " , $rot_result, stringify!( $SelfT) , ";
2253
+ let m = " , $rot_op, ";
2254
+
2255
+ assert_eq!(n.rotate_right(" , $rot, "), m);
2256
+ ```" ) ,
2257
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2258
+ #[ inline]
2259
+ pub fn rotate_right( self , n: u32 ) -> Self {
2260
+ // Protect against undefined behaviour for over-long bit shifts
2261
+ let n = n % $BITS;
2262
+ ( self >> n) | ( self << ( ( $BITS - n) % $BITS) )
2263
+ }
2264
2264
}
2265
2265
2266
2266
/// Reverses the byte order of the integer.
@@ -3621,7 +3621,7 @@ $EndFeature, "
3621
3621
3622
3622
#[ lang = "u8" ]
3623
3623
impl u8 {
3624
- uint_impl ! { u8 , u8 , 8 , 255 , "" , "" }
3624
+ uint_impl ! { u8 , u8 , 8 , 255 , "" , "" , 2 , "0x82" , "0xa" }
3625
3625
3626
3626
3627
3627
/// Checks if the value is within the ASCII range.
@@ -4147,39 +4147,41 @@ impl u8 {
4147
4147
4148
4148
#[ lang = "u16" ]
4149
4149
impl u16 {
4150
- uint_impl ! { u16 , u16 , 16 , 65535 , "" , "" }
4150
+ uint_impl ! { u16 , u16 , 16 , 65535 , "" , "" , 4 , "0xa003" , "0x3a" }
4151
4151
}
4152
4152
4153
4153
#[ lang = "u32" ]
4154
4154
impl u32 {
4155
- uint_impl ! { u32 , u32 , 32 , 4294967295 , "" , "" }
4155
+ uint_impl ! { u32 , u32 , 32 , 4294967295 , "" , "" , 8 , "0x10000b3" , "0xb301" }
4156
4156
}
4157
4157
4158
4158
#[ lang = "u64" ]
4159
4159
impl u64 {
4160
- uint_impl ! { u64 , u64 , 64 , 18446744073709551615 , "" , "" }
4160
+ uint_impl ! { u64 , u64 , 64 , 18446744073709551615 , "" , "" , 12 , "0xaa00000000006e1" , "0x6e10aa" }
4161
4161
}
4162
4162
4163
4163
#[ lang = "u128" ]
4164
4164
impl u128 {
4165
- uint_impl ! { u128 , u128 , 128 , 340282366920938463463374607431768211455 , "" , "" }
4165
+ uint_impl ! { u128 , u128 , 128 , 340282366920938463463374607431768211455 , "" , "" , 16 ,
4166
+ "0x13f40000000000000000000000004f76" , "0x4f7613f4" }
4166
4167
}
4167
4168
4168
4169
#[ cfg( target_pointer_width = "16" ) ]
4169
4170
#[ lang = "usize" ]
4170
4171
impl usize {
4171
- uint_impl ! { usize , u16 , 16 , 65536 , "" , "" }
4172
+ uint_impl ! { usize , u16 , 16 , 65536 , "" , "" , 4 , "0xa003" , "0x3a" }
4172
4173
}
4173
4174
#[ cfg( target_pointer_width = "32" ) ]
4174
4175
#[ lang = "usize" ]
4175
4176
impl usize {
4176
- uint_impl ! { usize , u32 , 32 , 4294967295 , "" , "" }
4177
+ uint_impl ! { usize , u32 , 32 , 4294967295 , "" , "" , 8 , "0x10000b3" , "0xb301" }
4177
4178
}
4178
4179
4179
4180
#[ cfg( target_pointer_width = "64" ) ]
4180
4181
#[ lang = "usize" ]
4181
4182
impl usize {
4182
- uint_impl ! { usize , u64 , 64 , 18446744073709551615 , "" , "" }
4183
+ uint_impl ! { usize , u64 , 64 , 18446744073709551615 , "" , "" , 12 , "0xaa00000000006e1" ,
4184
+ "0x6e10aa" }
4183
4185
}
4184
4186
4185
4187
/// A classification of floating point numbers.
0 commit comments