Skip to content

Commit 434cb5e

Browse files
committed
document behavior of rotations for n >= BITS
1 parent bc809be commit 434cb5e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

library/core/src/num/int_macros.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ macro_rules! int_impl {
275275
/// Shifts the bits to the left by a specified amount, `n`,
276276
/// wrapping the truncated bits to the end of the resulting integer.
277277
///
278+
/// `rotate_left(n)` is equivalent to applying `rotate_left(1)` a total of `n` times. In
279+
/// particular, a rotation by the number of bits in `self` returns the input value
280+
/// unchanged.
281+
///
278282
/// Please note this isn't the same operation as the `<<` shifting operator!
279283
///
280284
/// # Examples
@@ -284,6 +288,7 @@ macro_rules! int_impl {
284288
#[doc = concat!("let m = ", $rot_result, ";")]
285289
///
286290
#[doc = concat!("assert_eq!(n.rotate_left(", $rot, "), m);")]
291+
#[doc = concat!("assert_eq!(n.rotate_left(1024), n);")]
287292
/// ```
288293
#[stable(feature = "rust1", since = "1.0.0")]
289294
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
@@ -298,6 +303,10 @@ macro_rules! int_impl {
298303
/// wrapping the truncated bits to the beginning of the resulting
299304
/// integer.
300305
///
306+
/// `rotate_right(n)` is equivalent to applying `rotate_right(1)` a total of `n` times. In
307+
/// particular, a rotation by the number of bits in `self` returns the input value
308+
/// unchanged.
309+
///
301310
/// Please note this isn't the same operation as the `>>` shifting operator!
302311
///
303312
/// # Examples
@@ -307,6 +316,7 @@ macro_rules! int_impl {
307316
#[doc = concat!("let m = ", $rot_op, ";")]
308317
///
309318
#[doc = concat!("assert_eq!(n.rotate_right(", $rot, "), m);")]
319+
#[doc = concat!("assert_eq!(n.rotate_right(1024), n);")]
310320
/// ```
311321
#[stable(feature = "rust1", since = "1.0.0")]
312322
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]

library/core/src/num/uint_macros.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ macro_rules! uint_impl {
336336
/// Shifts the bits to the left by a specified amount, `n`,
337337
/// wrapping the truncated bits to the end of the resulting integer.
338338
///
339+
/// `rotate_left(n)` is equivalent to applying `rotate_left(1)` a total of `n` times. In
340+
/// particular, a rotation by the number of bits in `self` returns the input value
341+
/// unchanged.
342+
///
339343
/// Please note this isn't the same operation as the `<<` shifting operator!
340344
///
341345
/// # Examples
@@ -345,6 +349,7 @@ macro_rules! uint_impl {
345349
#[doc = concat!("let m = ", $rot_result, ";")]
346350
///
347351
#[doc = concat!("assert_eq!(n.rotate_left(", $rot, "), m);")]
352+
#[doc = concat!("assert_eq!(n.rotate_left(1024), n);")]
348353
/// ```
349354
#[stable(feature = "rust1", since = "1.0.0")]
350355
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
@@ -360,6 +365,10 @@ macro_rules! uint_impl {
360365
/// wrapping the truncated bits to the beginning of the resulting
361366
/// integer.
362367
///
368+
/// `rotate_right(n)` is equivalent to applying `rotate_right(1)` a total of `n` times. In
369+
/// particular, a rotation by the number of bits in `self` returns the input value
370+
/// unchanged.
371+
///
363372
/// Please note this isn't the same operation as the `>>` shifting operator!
364373
///
365374
/// # Examples
@@ -369,6 +378,7 @@ macro_rules! uint_impl {
369378
#[doc = concat!("let m = ", $rot_op, ";")]
370379
///
371380
#[doc = concat!("assert_eq!(n.rotate_right(", $rot, "), m);")]
381+
#[doc = concat!("assert_eq!(n.rotate_right(1024), n);")]
372382
/// ```
373383
#[stable(feature = "rust1", since = "1.0.0")]
374384
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]

0 commit comments

Comments
 (0)