From 3725a5d9d03604d0170b23ac7eeedbd5321bbf8c Mon Sep 17 00:00:00 2001 From: Jason Travis Smith Date: Sat, 1 Jul 2017 16:02:57 -0400 Subject: [PATCH] Added a min() and max() function for all Numbers. --- src/number.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/number.rs b/src/number.rs index 6a31880..b643e99 100644 --- a/src/number.rs +++ b/src/number.rs @@ -15,7 +15,7 @@ use ::bounded::Bounded; pub trait Number : Zero + One + Add + Sub + Mul + Div + Rem + AddAssign + SubAssign + MulAssign + - DivAssign + RemAssign + PartialEq + + DivAssign + RemAssign + PartialEq + PartialOrd + Copy + Clone + Debug + Display { type StrRadixError; @@ -30,6 +30,32 @@ pub trait Number : Zero + One + Add + Sub + + /// + 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. /// ///```