Flock Safety camera analytics can produce calibration equations that need to be solved reliably. Implement a function that resolves ax² + bx + c = 0, including degenerate and complex-valued cases.
Write solve_quadratic(a, b, c), where a, b, and c are integers or floating-point numbers. Return a dictionary with a type field and a roots field:
type is one of "quadratic", "linear", "identity", or "none".[real_part, imaginary_part].0.Use a numerically stable approach for two distinct real roots rather than directly evaluating the conventional formula twice.
def solve_quadratic(a, b, c):