Added a min() and max() function for all Numbers.
This commit is contained in:
parent
be9cd149ac
commit
3725a5d9d0
@ -15,7 +15,7 @@ use ::bounded::Bounded;
|
||||
pub trait Number : Zero + One + Add<Output=Self> + Sub<Output=Self> +
|
||||
Mul<Output=Self> + Div<Output=Self> + Rem<Output=Self> +
|
||||
AddAssign<Self> + SubAssign<Self> + MulAssign<Self> +
|
||||
DivAssign<Self> + RemAssign<Self> + PartialEq +
|
||||
DivAssign<Self> + RemAssign<Self> + PartialEq + PartialOrd +
|
||||
Copy + Clone + Debug + Display
|
||||
{
|
||||
type StrRadixError;
|
||||
@ -30,6 +30,32 @@ pub trait Number : Zero + One + Add<Output=Self> + Sub<Output=Self> +
|
||||
|
||||
|
||||
|
||||
///
|
||||
fn max(self, other: Self) -> Self
|
||||
{
|
||||
if self >= other
|
||||
{
|
||||
self
|
||||
}
|
||||
else
|
||||
{
|
||||
other
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
fn min(self, other: Self) -> Self
|
||||
{
|
||||
if self <= other
|
||||
{
|
||||
self
|
||||
}
|
||||
else
|
||||
{
|
||||
other
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a number from a given string and base radix.
|
||||
///
|
||||
///```
|
||||
|
Loading…
x
Reference in New Issue
Block a user