Skip to content

Commit

Permalink
Add docs for saturating integer arithmetic.
Browse files Browse the repository at this point in the history
This was added for #23241.
  • Loading branch information
jbcrail committed Mar 11, 2015
1 parent f899513 commit 62be565
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 62be565

Please sign in to comment.