Skip to content

introduce type PolynomialDegree #213

@jan-ferdinand

Description

@jan-ferdinand

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

enum Degree {
    Positive(usize), // placeholder name, suggestions welcome
    NegativeInfinity,
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestprio: low⏭️ breaking changeBreaking change, will require an increment of the major version number. E.g: 0.3.0 -> 0.4.0

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions