Skip to content

Commit e98e391

Browse files
committed
Auto merge of #23254 - jbcrail:saturating-math-docs, r=steveklabnik
This was added for #23241.
2 parents f4e0ce6 + 62be565 commit e98e391

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libcore/num/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ pub trait Int
345345

346346
/// Saturating integer addition. Computes `self + other`, saturating at
347347
/// the numeric bounds instead of overflowing.
348+
///
349+
/// # Examples
350+
///
351+
/// ```
352+
/// use std::num::Int;
353+
///
354+
/// assert_eq!(5u16.saturating_add(65534), 65535);
355+
/// assert_eq!((-5i16).saturating_add(-32767), -32768);
356+
/// assert_eq!(100u32.saturating_add(4294967294), 4294967295);
357+
/// ```
348358
#[stable(feature = "rust1", since = "1.0.0")]
349359
#[inline]
350360
fn saturating_add(self, other: Self) -> Self {
@@ -357,6 +367,16 @@ pub trait Int
357367

358368
/// Saturating integer subtraction. Computes `self - other`, saturating at
359369
/// the numeric bounds instead of overflowing.
370+
///
371+
/// # Examples
372+
///
373+
/// ```
374+
/// use std::num::Int;
375+
///
376+
/// assert_eq!(5u16.saturating_sub(65534), 0);
377+
/// assert_eq!(5i16.saturating_sub(-32767), 32767);
378+
/// assert_eq!(100u32.saturating_sub(4294967294), 0);
379+
/// ```
360380
#[stable(feature = "rust1", since = "1.0.0")]
361381
#[inline]
362382
fn saturating_sub(self, other: Self) -> Self {

0 commit comments

Comments
 (0)