pub fn real_roots(coefficients: &[f64], touch: f64, out: &mut [f64]) -> usizeExpand description
The real roots of a polynomial, in increasing order, written to the front
of out; returns how many there are.
coefficients are in ascending power order, as for roots; leading
coefficients that are exactly zero are dropped. Nothing is allocated up
to degree 16.
The derivative’s real roots, found the same way down to a line, split
the real line into intervals on which the polynomial is monotone. Each
interval whose ends differ in sign holds one root, which safeguarded
Newton finds with bisection to fall back on (Yuksel, “High-Performance
Polynomial Root Finding for Graphics”, HPG 2022). A root of even
multiplicity, a tangency, has no sign change around it: it is a critical
point where the polynomial’s value is zero to rounding, or no larger
than touch with no root on either side. touch is in the polynomial’s
own units, since only the caller knows what rounding its coefficients
carry. Such a root comes back once. Two simple roots whose critical
point between them has a value within that rounding (or within touch)
come back as the one root there: for a quartic with roots near one, a
pair a few times 1e-7 apart.
A polynomial whose every coefficient is zero, or one that is not finite, has no roots returned.
§Panics
If out has room for fewer values than the polynomial’s degree.