Merge rust-bitcoin/rust-bitcoin#2527: Tidy description
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: ACKe3db95226a
oops, we should have caught this. Thanks for the fix! tcharding: ACKe3db95226a
Tree-SHA512: 8a2e7f85262f17063bea6ac22855ae45d99a1559a2d30f2627ffba1108f0fd8ebd0b541b50fe746b5af2ebb013cb3e9ea432987b90f37c046120388a808c5443
This commit is contained in:
commit
6f14a1031a
|
@ -988,34 +988,38 @@ impl Amount {
|
|||
// Some arithmetic that doesn't fit in `core::ops` traits.
|
||||
|
||||
/// Checked addition.
|
||||
///
|
||||
/// Returns [None] if overflow occurred.
|
||||
pub fn checked_add(self, rhs: Amount) -> Option<Amount> {
|
||||
self.0.checked_add(rhs.0).map(Amount)
|
||||
}
|
||||
|
||||
/// Checked subtraction.
|
||||
///
|
||||
/// Returns [None] if overflow occurred.
|
||||
pub fn checked_sub(self, rhs: Amount) -> Option<Amount> {
|
||||
self.0.checked_sub(rhs.0).map(Amount)
|
||||
}
|
||||
|
||||
/// Checked multiplication.
|
||||
///
|
||||
/// Returns [None] if overflow occurred.
|
||||
pub fn checked_mul(self, rhs: u64) -> Option<Amount> { self.0.checked_mul(rhs).map(Amount) }
|
||||
|
||||
/// Checked integer division.
|
||||
///
|
||||
/// Be aware that integer division loses the remainder if no exact division
|
||||
/// can be made.
|
||||
/// Returns [None] if overflow occurred.
|
||||
pub fn checked_div(self, rhs: u64) -> Option<Amount> { self.0.checked_div(rhs).map(Amount) }
|
||||
|
||||
/// Checked remainder.
|
||||
///
|
||||
/// Returns [None] if overflow occurred.
|
||||
pub fn checked_rem(self, rhs: u64) -> Option<Amount> { self.0.checked_rem(rhs).map(Amount) }
|
||||
|
||||
/// Unchecked addition.
|
||||
///
|
||||
///
|
||||
/// Computes `self + rhs`. Panics in debug mode, wraps in release mode.
|
||||
pub fn unchecked_add(self, rhs: Amount) -> Amount {
|
||||
Self(self.0 + rhs.0)
|
||||
|
|
Loading…
Reference in New Issue