Hello,
Assuming you have resources to accommodate floating point mathematics, the following untested function should give the solutions to the quadradic equation, for both real and complex cases.
#include "math.h"
/* Global variables for result */
double r1, i1; // First solution
double r2, i2; // Second solution
void quadratic (double a, double b, double c)
{
double t;
b = b/a;
c = c/a;
t = b*b/2 - c;
if (t < 0) {
/* Complex solution */
r1 = -0.5*b;
i1 = sqrt(-t);
r2 = r1;
i2 = -i1;
}
else {
/* Real solution */
t = sqrt(t);
r1 = -0.5*b + t;
i1 = 0;
r2 = -0.5*b - t;
i2 = 0;
}
}
For the coefficients given in your post, the solution will be complex -
-2+j1, -2-j1
Regards,
Mac