Skip to content

Commit 38ea07f

Browse files
Rollup merge of rust-lang#157900 - elanortang:main, r=RalfJung
Update intrinsics wrapping documentation This PR updates the documentation for `intrinsics::{wrapping_add, wrapping_sub, wrapping_mul}`, to make it accurate for both signed and unsigned types. Related issue: rust-lang#156726
2 parents 4d691a0 + 61006a0 commit 38ea07f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • library/core/src/intrinsics

library/core/src/intrinsics/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,8 @@ pub const fn rotate_right<T: [const] fallback::FunnelShift>(x: T, shift: u32) ->
20592059
unsafe { unchecked_funnel_shr(x, x, shift % (mem::size_of::<T>() as u32 * 8)) }
20602060
}
20612061

2062-
/// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
2062+
/// Wrapping (modular) addition. Computes `a + b`,
2063+
/// wrapping around at the boundary of the type.
20632064
///
20642065
/// Note that, unlike most intrinsics, this is safe to call;
20652066
/// it does not require an `unsafe` block.
@@ -2073,7 +2074,8 @@ pub const fn rotate_right<T: [const] fallback::FunnelShift>(x: T, shift: u32) ->
20732074
#[rustc_nounwind]
20742075
#[rustc_intrinsic]
20752076
pub const fn wrapping_add<T: Copy>(a: T, b: T) -> T;
2076-
/// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
2077+
/// Wrapping (modular) subtraction. Computes `a - b`,
2078+
/// wrapping around at the boundary of the type.
20772079
///
20782080
/// Note that, unlike most intrinsics, this is safe to call;
20792081
/// it does not require an `unsafe` block.
@@ -2087,7 +2089,8 @@ pub const fn wrapping_add<T: Copy>(a: T, b: T) -> T;
20872089
#[rustc_nounwind]
20882090
#[rustc_intrinsic]
20892091
pub const fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
2090-
/// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
2092+
/// Wrapping (modular) multiplication. Computes `a *
2093+
/// b`, wrapping around at the boundary of the type.
20912094
///
20922095
/// Note that, unlike most intrinsics, this is safe to call;
20932096
/// it does not require an `unsafe` block.

0 commit comments

Comments
 (0)