I find the amount of polynomial.degree() as usize in our codebase concerning, especially since .degree() returns an isize. This can cause some very funny behavior. I suggest we express a polynomial's degree as an
and provide convenience methods as we see fit. For example, a common pattern is to panic! if the degree is NegativeInfinity (currently -1), which could be expressed through:
impl Polynomial {
/// # Panics
///
/// Panics if `self` is the zero polynomial.
fn positive_degree(&self) -> usize {
let Degree::Positive(degree) = self.degree() else {
panic!("you messed up");
}
degree
}
}
I find the amount of
polynomial.degree() as usize
in our codebase concerning, especially since.degree()
returns anisize
. This can cause some very funny behavior. I suggest we express a polynomial's degree as anand provide convenience methods as we see fit. For example, a common pattern is to
panic!
if the degree isNegativeInfinity
(currently-1
), which could be expressed through: