Skip to content

Commit

Permalink
Rollup merge of rust-lang#46947 - tspiteri:checked-div-rem-none, r=fr…
Browse files Browse the repository at this point in the history
…ewsxcv

doc: improve None condition doc for `checked_div` and `checked_rem`

This commit improves the condition mentioned in the docs for which `checked_div` and `checked_rem` return `None`.

For signed division, the commit changes "the operation results in overflow" to "the division results in overflow", otherwise there is room for misinterpretation for `checked_rem`: Without considering overflow, `MIN % -1` would be simply zero, allowing the misinterpretation that "the operation" does not result in overflow in this case. This ambiguity is removed using "when the division results in overflow".

For unsigned division, the condition for `None` should be simply when `rhs == 0`, as no other overflow is possible.
  • Loading branch information
kennytm authored Jan 6, 2018
2 parents 72176cf + f2c5472 commit d9d5c66
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ macro_rules! int_impl {
}

/// Checked integer division. Computes `self / rhs`, returning `None`
/// if `rhs == 0` or the operation results in overflow.
/// if `rhs == 0` or the division results in overflow.
///
/// # Examples
///
Expand All @@ -461,7 +461,7 @@ macro_rules! int_impl {
}

/// Checked integer remainder. Computes `self % rhs`, returning `None`
/// if `rhs == 0` or the operation results in overflow.
/// if `rhs == 0` or the division results in overflow.
///
/// # Examples
///
Expand Down Expand Up @@ -1607,7 +1607,7 @@ macro_rules! uint_impl {
}

/// Checked integer division. Computes `self / rhs`, returning `None`
/// if `rhs == 0` or the operation results in overflow.
/// if `rhs == 0`.
///
/// # Examples
///
Expand All @@ -1627,7 +1627,7 @@ macro_rules! uint_impl {
}

/// Checked integer remainder. Computes `self % rhs`, returning `None`
/// if `rhs == 0` or the operation results in overflow.
/// if `rhs == 0`.
///
/// # Examples
///
Expand Down

0 comments on commit d9d5c66

Please sign in to comment.