Skip to content

Commit e8cb7b0

Browse files
committed
Fix checked operations documentation.
- Remove the implication that wrapping is the default behaviour for `CheckedEuclid` methods. - Replace mentions of 'underflow' with 'overflow'.
1 parent e92f633 commit e8cb7b0

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/ops/checked.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ checked_impl!(CheckedAdd, checked_add, i64);
3232
checked_impl!(CheckedAdd, checked_add, isize);
3333
checked_impl!(CheckedAdd, checked_add, i128);
3434

35-
/// Performs subtraction, returning `None` if underflow occurred.
35+
/// Performs subtraction, returning `None` if overflow occurred.
3636
pub trait CheckedSub: Sized + Sub<Self, Output = Self> {
37-
/// Subtracts two numbers, checking for underflow. If underflow happens,
37+
/// Subtracts two numbers, checking for overflow. If overflow happens,
3838
/// `None` is returned.
3939
fn checked_sub(&self, v: &Self) -> Option<Self>;
4040
}
@@ -53,11 +53,10 @@ checked_impl!(CheckedSub, checked_sub, i64);
5353
checked_impl!(CheckedSub, checked_sub, isize);
5454
checked_impl!(CheckedSub, checked_sub, i128);
5555

56-
/// Performs multiplication, returning `None` if underflow or overflow
57-
/// occurred.
56+
/// Performs multiplication, returning `None` if overflow occurred.
5857
pub trait CheckedMul: Sized + Mul<Self, Output = Self> {
59-
/// Multiplies two numbers, checking for underflow or overflow. If underflow
60-
/// or overflow happens, `None` is returned.
58+
/// Multiplies two numbers, checking for overflow. If overflow happens,
59+
/// `None` is returned.
6160
fn checked_mul(&self, v: &Self) -> Option<Self>;
6261
}
6362

@@ -75,10 +74,10 @@ checked_impl!(CheckedMul, checked_mul, i64);
7574
checked_impl!(CheckedMul, checked_mul, isize);
7675
checked_impl!(CheckedMul, checked_mul, i128);
7776

78-
/// Performs division, returning `None` on division by zero or if underflow or
79-
/// overflow occurred.
77+
/// Performs division, returning `None` on division by zero or if overflow
78+
/// occurred.
8079
pub trait CheckedDiv: Sized + Div<Self, Output = Self> {
81-
/// Divides two numbers, checking for underflow, overflow and division by
80+
/// Divides two numbers, checking for overflow and division by
8281
/// zero. If any of that happens, `None` is returned.
8382
fn checked_div(&self, v: &Self) -> Option<Self>;
8483
}
@@ -98,10 +97,10 @@ checked_impl!(CheckedDiv, checked_div, isize);
9897
checked_impl!(CheckedDiv, checked_div, i128);
9998

10099
/// Performs integral remainder, returning `None` on division by zero or if
101-
/// underflow or overflow occurred.
100+
/// overflow occurred.
102101
pub trait CheckedRem: Sized + Rem<Self, Output = Self> {
103-
/// Finds the remainder of dividing two numbers, checking for underflow, overflow and division
104-
/// by zero. If any of that happens, `None` is returned.
102+
/// Finds the remainder of dividing two numbers, checking for overflow and
103+
/// division by zero. If any of that happens, `None` is returned.
105104
///
106105
/// # Examples
107106
///

src/ops/euclid.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,16 @@ impl Euclid for f64 {
136136
}
137137

138138
pub trait CheckedEuclid: Euclid {
139-
/// Performs euclid division that returns `None` instead of panicking on division by zero
140-
/// and instead of wrapping around on underflow and overflow.
139+
/// Performs euclid division, returning `None` on division by zero or if
140+
/// overflow occurred.
141141
fn checked_div_euclid(&self, v: &Self) -> Option<Self>;
142142

143-
/// Finds the euclid remainder of dividing two numbers, checking for underflow, overflow and
144-
/// division by zero. If any of that happens, `None` is returned.
143+
/// Finds the euclid remainder of dividing two numbers, returning `None` on
144+
/// division by zero or if overflow occurred.
145145
fn checked_rem_euclid(&self, v: &Self) -> Option<Self>;
146146

147-
/// Returns both the quotient and remainder from checked Euclidean division.
147+
/// Returns both the quotient and remainder from checked Euclidean division,
148+
/// returning `None` on division by zero or if overflow occurred.
148149
///
149150
/// By default, it internally calls both `CheckedEuclid::checked_div_euclid` and `CheckedEuclid::checked_rem_euclid`,
150151
/// but it can be overridden in order to implement some optimization.

0 commit comments

Comments
 (0)