Skip to content

Commit

Permalink
Auto merge of #23254 - jbcrail:saturating-math-docs, r=steveklabnik
Browse files Browse the repository at this point in the history
This was added for #23241.
  • Loading branch information
bors committed Mar 20, 2015
2 parents f4e0ce6 + 62be565 commit e98e391
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ pub trait Int

/// Saturating integer addition. Computes `self + other`, saturating at
/// the numeric bounds instead of overflowing.
///
/// # Examples
///
/// ```
/// use std::num::Int;
///
/// assert_eq!(5u16.saturating_add(65534), 65535);
/// assert_eq!((-5i16).saturating_add(-32767), -32768);
/// assert_eq!(100u32.saturating_add(4294967294), 4294967295);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn saturating_add(self, other: Self) -> Self {
Expand All @@ -357,6 +367,16 @@ pub trait Int

/// Saturating integer subtraction. Computes `self - other`, saturating at
/// the numeric bounds instead of overflowing.
///
/// # Examples
///
/// ```
/// use std::num::Int;
///
/// assert_eq!(5u16.saturating_sub(65534), 0);
/// assert_eq!(5i16.saturating_sub(-32767), 32767);
/// assert_eq!(100u32.saturating_sub(4294967294), 0);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn saturating_sub(self, other: Self) -> Self {
Expand Down

0 comments on commit e98e391

Please sign in to comment.