Skip to content

Commit

Permalink
Add division by zero case to the CheckedDiv comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Aug 8, 2014
1 parent 3b1f983 commit cd6eb12
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,17 +1345,19 @@ checked_impl!(CheckedMul, checked_mul, i16, intrinsics::i16_mul_with_overflow)
checked_impl!(CheckedMul, checked_mul, i32, intrinsics::i32_mul_with_overflow)
checked_impl!(CheckedMul, checked_mul, i64, intrinsics::i64_mul_with_overflow)

/// Performs division that returns `None` instead of wrapping around on underflow or overflow.
/// Performs division that returns `None` instead of failing on division by zero and instead of
/// wrapping around on underflow and overflow.
pub trait CheckedDiv: Div<Self, Self> {
/// Divides two numbers, checking for underflow or overflow. If underflow or overflow happens,
/// `None` is returned.
/// Divides two numbers, checking for underflow, overflow and division by zero. If any of that
/// happens, / `None` is returned.
///
/// # Example
///
/// ```rust
/// use std::num::CheckedDiv;
/// assert_eq!((-127i8).checked_div(&-1), Some(127));
/// assert_eq!((-128i8).checked_div(&-1), None);
/// assert_eq!((1i8).checked_div(&0), None);
/// ```
fn checked_div(&self, v: &Self) -> Option<Self>;
}
Expand Down

5 comments on commit cd6eb12

@bors
Copy link
Contributor

@bors bors commented on cd6eb12 Aug 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at tbu-@cd6eb12

@bors
Copy link
Contributor

@bors bors commented on cd6eb12 Aug 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging tbu-/rust/pr_checkeddiv0 = cd6eb12 into auto

@bors
Copy link
Contributor

@bors bors commented on cd6eb12 Aug 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbu-/rust/pr_checkeddiv0 = cd6eb12 merged ok, testing candidate = d16a5cd

@bors
Copy link
Contributor

@bors bors commented on cd6eb12 Aug 19, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = d16a5cd

Please sign in to comment.