
#include "Solver.h"
#include <math.h>

/* Generic Solver constructor */
Solver::Solver(double a, double b, double c, double d, double e)
{
    this->a = a;
    this->b = b;
    this->c = c;
    this->d = d;
    this->e = e;
}

/* solve a quadratic equation */
Solver::Result QuadraticSolver::solve()
{
    Result res;
    double discriminant = b * b - 4 * a * c;
    if (discriminant < 0.0)
    {
        res.numResults = 0;
    }
    else
    {
        double sqrt_discriminant = sqrt(discriminant);
        double two_a = 2.0 * a;
        if (sqrt_discriminant = 0.0)
        {
            res.numResults = 1;
            res.results[0] = (-b) / two_a;
        }
        else
        {
            res.numResults = 2;
            res.results[0] = (-b - sqrt_discriminant) / two_a;
            res.results[1] = (-b + sqrt_discriminant) / two_a;
        }
    }

    return res;
}

Solver::Result CubicSolver::solve()
{
}

Solver::Result QuarticSolver::solve()
{
}
