e3db95226a Tidy description (yancy)

Pull request description:

  I noticed `uncheced_add` looked really bad with two spaces (my mistake).  Fixed some others as well.

ACKs for top commit:
  apoelstra:
    ACK e3db95226a oops, we should have caught this. Thanks for the fix!
  tcharding:
    ACK e3db95226a

Tree-SHA512: 8a2e7f85262f17063bea6ac22855ae45d99a1559a2d30f2627ffba1108f0fd8ebd0b541b50fe746b5af2ebb013cb3e9ea432987b90f37c046120388a808c5443
This commit is contained in:
Andrew Poelstra 2024-02-29 21:04:24 +00:00
commit 6f14a1031a
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 5 additions and 1 deletions

View File

@ -988,34 +988,38 @@ impl Amount {
// Some arithmetic that doesn't fit in `core::ops` traits. // Some arithmetic that doesn't fit in `core::ops` traits.
/// Checked addition. /// Checked addition.
///
/// Returns [None] if overflow occurred. /// Returns [None] if overflow occurred.
pub fn checked_add(self, rhs: Amount) -> Option<Amount> { pub fn checked_add(self, rhs: Amount) -> Option<Amount> {
self.0.checked_add(rhs.0).map(Amount) self.0.checked_add(rhs.0).map(Amount)
} }
/// Checked subtraction. /// Checked subtraction.
///
/// Returns [None] if overflow occurred. /// Returns [None] if overflow occurred.
pub fn checked_sub(self, rhs: Amount) -> Option<Amount> { pub fn checked_sub(self, rhs: Amount) -> Option<Amount> {
self.0.checked_sub(rhs.0).map(Amount) self.0.checked_sub(rhs.0).map(Amount)
} }
/// Checked multiplication. /// Checked multiplication.
///
/// Returns [None] if overflow occurred. /// Returns [None] if overflow occurred.
pub fn checked_mul(self, rhs: u64) -> Option<Amount> { self.0.checked_mul(rhs).map(Amount) } pub fn checked_mul(self, rhs: u64) -> Option<Amount> { self.0.checked_mul(rhs).map(Amount) }
/// Checked integer division. /// Checked integer division.
///
/// Be aware that integer division loses the remainder if no exact division /// Be aware that integer division loses the remainder if no exact division
/// can be made. /// can be made.
/// Returns [None] if overflow occurred. /// Returns [None] if overflow occurred.
pub fn checked_div(self, rhs: u64) -> Option<Amount> { self.0.checked_div(rhs).map(Amount) } pub fn checked_div(self, rhs: u64) -> Option<Amount> { self.0.checked_div(rhs).map(Amount) }
/// Checked remainder. /// Checked remainder.
///
/// Returns [None] if overflow occurred. /// Returns [None] if overflow occurred.
pub fn checked_rem(self, rhs: u64) -> Option<Amount> { self.0.checked_rem(rhs).map(Amount) } pub fn checked_rem(self, rhs: u64) -> Option<Amount> { self.0.checked_rem(rhs).map(Amount) }
/// Unchecked addition. /// Unchecked addition.
/// ///
///
/// Computes `self + rhs`. Panics in debug mode, wraps in release mode. /// Computes `self + rhs`. Panics in debug mode, wraps in release mode.
pub fn unchecked_add(self, rhs: Amount) -> Amount { pub fn unchecked_add(self, rhs: Amount) -> Amount {
Self(self.0 + rhs.0) Self(self.0 + rhs.0)