Skip to main content

solve_quadratic

Function solve_quadratic 

Source
pub fn solve_quadratic(
    a: f64,
    b: f64,
    c: f64,
) -> Result<QuadraticRoots, SolversError>
Expand description

Solve a·x² + b·x + c = 0 over the reals, numerically stably.

Uses the cancellation-avoiding form q = -(b + sign(b)·√Δ)/2, roots q/a and c/q, for Δ > 0; classifies Δ ≈ 0 as a double root and Δ < 0 as a complex pair. Falls back to the linear root when a ≈ 0. Returns SolversError::ComputationError for a non-finite or fully-degenerate input.