document behavior of rotations for n >= BITS

This commit is contained in:
Ralf Jung
2025-11-04 15:33:11 +01:00
parent bc809befe2
commit 434cb5e700
2 changed files with 20 additions and 0 deletions
+10
View File
@@ -275,6 +275,10 @@ pub const fn cast_unsigned(self) -> $UnsignedT {
/// Shifts the bits to the left by a specified amount, `n`,
/// wrapping the truncated bits to the end of the resulting integer.
///
/// `rotate_left(n)` is equivalent to applying `rotate_left(1)` a total of `n` times. In
/// particular, a rotation by the number of bits in `self` returns the input value
/// unchanged.
///
/// Please note this isn't the same operation as the `<<` shifting operator!
///
/// # Examples
@@ -284,6 +288,7 @@ pub const fn cast_unsigned(self) -> $UnsignedT {
#[doc = concat!("let m = ", $rot_result, ";")]
///
#[doc = concat!("assert_eq!(n.rotate_left(", $rot, "), m);")]
#[doc = concat!("assert_eq!(n.rotate_left(1024), n);")]
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
@@ -298,6 +303,10 @@ pub const fn rotate_left(self, n: u32) -> Self {
/// wrapping the truncated bits to the beginning of the resulting
/// integer.
///
/// `rotate_right(n)` is equivalent to applying `rotate_right(1)` a total of `n` times. In
/// particular, a rotation by the number of bits in `self` returns the input value
/// unchanged.
///
/// Please note this isn't the same operation as the `>>` shifting operator!
///
/// # Examples
@@ -307,6 +316,7 @@ pub const fn rotate_left(self, n: u32) -> Self {
#[doc = concat!("let m = ", $rot_op, ";")]
///
#[doc = concat!("assert_eq!(n.rotate_right(", $rot, "), m);")]
#[doc = concat!("assert_eq!(n.rotate_right(1024), n);")]
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
+10
View File
@@ -336,6 +336,10 @@ pub const fn cast_signed(self) -> $SignedT {
/// Shifts the bits to the left by a specified amount, `n`,
/// wrapping the truncated bits to the end of the resulting integer.
///
/// `rotate_left(n)` is equivalent to applying `rotate_left(1)` a total of `n` times. In
/// particular, a rotation by the number of bits in `self` returns the input value
/// unchanged.
///
/// Please note this isn't the same operation as the `<<` shifting operator!
///
/// # Examples
@@ -345,6 +349,7 @@ pub const fn cast_signed(self) -> $SignedT {
#[doc = concat!("let m = ", $rot_result, ";")]
///
#[doc = concat!("assert_eq!(n.rotate_left(", $rot, "), m);")]
#[doc = concat!("assert_eq!(n.rotate_left(1024), n);")]
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
@@ -360,6 +365,10 @@ pub const fn rotate_left(self, n: u32) -> Self {
/// wrapping the truncated bits to the beginning of the resulting
/// integer.
///
/// `rotate_right(n)` is equivalent to applying `rotate_right(1)` a total of `n` times. In
/// particular, a rotation by the number of bits in `self` returns the input value
/// unchanged.
///
/// Please note this isn't the same operation as the `>>` shifting operator!
///
/// # Examples
@@ -369,6 +378,7 @@ pub const fn rotate_left(self, n: u32) -> Self {
#[doc = concat!("let m = ", $rot_op, ";")]
///
#[doc = concat!("assert_eq!(n.rotate_right(", $rot, "), m);")]
#[doc = concat!("assert_eq!(n.rotate_right(1024), n);")]
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]