Refactoring

This commit is contained in:
Fabian Schmidt 2024-11-22 14:17:04 +01:00
parent b44908429a
commit 1f96d76c74

View File

@ -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
}
}