function y=quadraticFormula(a,b,c)
% Roots of a quadratic equation:
% WISE usage of the quadratic formula:
% Special attention is paid to minimize rooundoff error,
% overflow and unnecessary underflow.
% The coefficients must all be real.
% The roots may be complex.
% K. Ming Leung, 01/09/03
% find the scale factor so that the largest coefficient has unit magnitude
scale=sign(b)*max([abs(a) abs(b) abs(c)]);
% scale the coefficients
a=a/scale;
b=b/scale;
c=c/scale;
if (a~=0)
d=b*b-4*a*c;
a2=2*a;
if (d>0)
% both real roots
ds=sqrt(d);
bds=-(b+ds)/2;
x2=bds/a;
x1=c/bds;
elseif (d<0)
% pair of complex roots
ds=sqrt(-d);
r1=-b/a2;
r2=ds/a2;
x1=r1+i*r2;
x2=conj(x1);
else
% d=0
x1=-b/a2;
x2=x1;
end;
else
% a=0
x1=-c/b;
x2=Inf;
end
y=[x1 x2];