diff --git a/src/number.rs b/src/number.rs index 8591b0a..8f12f43 100644 --- a/src/number.rs +++ b/src/number.rs @@ -427,35 +427,32 @@ impl Ord for Number { } else if self.sign == Sign::Positif && other.sign == Sign::Negatif { return Ordering::Greater; } - if self.digits.len() < other.digits.len() { - if self.sign == Sign::Positif { - return Ordering::Less; - } else if self.sign == Sign::Negatif { - return Ordering::Greater; - } - } else if self.digits.len() > other.digits.len() { - if self.sign == Sign::Positif { - return Ordering::Greater; - } else if self.sign == Sign::Negatif { - return Ordering::Less; + match self.digits.len().cmp(&other.digits.len()) { + Ordering::Less => match self.sign { + Sign::Positif => Ordering::Less, + Sign::Negatif => Ordering::Greater, + }, + Ordering::Greater => match self.sign { + Sign::Positif => Ordering::Greater, + Sign::Negatif => Ordering::Less, + }, + Ordering::Equal => { + for pair in zip(&self.digits, &other.digits) { + return match pair.0.cmp(pair.1) { + Ordering::Less => match self.sign { + Sign::Positif => Ordering::Less, + Sign::Negatif => Ordering::Greater, + }, + Ordering::Greater => match self.sign { + Sign::Positif => Ordering::Greater, + Sign::Negatif => Ordering::Less, + }, + Ordering::Equal => continue, + }; + } + Ordering::Equal } } - for pair in zip(&self.digits, &other.digits) { - if pair.0 < pair.1 { - if self.sign == Sign::Positif { - return Ordering::Less; - } else if self.sign == Sign::Negatif { - return Ordering::Greater; - } - } else if pair.0 > pair.1 { - if self.sign == Sign::Positif { - return Ordering::Greater; - } else if self.sign == Sign::Negatif { - return Ordering::Less; - } - } - } - Ordering::Equal } }