Skip to content

Commit

Permalink
Merge pull request #53 from MiguelX413/master
Browse files Browse the repository at this point in the history
Add Integer.dec() and Integer.inc()
  • Loading branch information
cuviper authored Feb 8, 2024
2 parents 9720c90 + 8682553 commit 77324ee
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,40 @@ pub trait Integer: Sized + Num + PartialOrd + Ord + Eq {
{
self.clone() - self.mod_floor(other)
}

/// Decrements self by one.
///
/// # Examples
///
/// ~~~
/// # use num_integer::Integer;
/// let mut x: i32 = 43;
/// x.dec();
/// assert_eq!(x, 42);
/// ~~~
fn dec(&mut self)
where
Self: Clone,
{
*self = self.clone() - Self::one()
}

/// Increments self by one.
///
/// # Examples
///
/// ~~~
/// # use num_integer::Integer;
/// let mut x: i32 = 41;
/// x.inc();
/// assert_eq!(x, 42);
/// ~~~
fn inc(&mut self)
where
Self: Clone,
{
*self = self.clone() + Self::one()
}
}

/// Greatest common divisor and Bézout coefficients
Expand Down

0 comments on commit 77324ee

Please sign in to comment.