diff options
| author | bors <bors@rust-lang.org> | 2014-08-19 06:50:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-08-19 06:50:55 +0000 |
| commit | d16a5cd7c4d37c947faf4661b22e994409197809 (patch) | |
| tree | 0f1f5e55df0fddc4c9cf503572f9ee93323fd335 | |
| parent | dee8313364185046670044f2f9faa0561166f882 (diff) | |
| parent | cd6eb122707f5f6dddffd871e9e54c4561e4e5f0 (diff) | |
| download | rust-d16a5cd7c4d37c947faf4661b22e994409197809.tar.gz rust-d16a5cd7c4d37c947faf4661b22e994409197809.zip | |
auto merge of #16364 : tbu-/rust/pr_checkeddiv0, r=alexcrichton
| -rw-r--r-- | src/libcore/num/mod.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 2b7249aca12..42f74ab429a 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1345,10 +1345,11 @@ 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 /// @@ -1356,6 +1357,7 @@ pub trait CheckedDiv: Div<Self, Self> { /// 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>; } |
