function [ns,sol] = F_SolRealEc2grado(a,b,c)

% Solve a second degree equation a*x^2+b*x+c=0
% Input:
%   a,b,c : equation coeffs
% Output:
%   ns        : number of real solutions 0<=ns<=2
%   sol(1:ns) : real solutions

% Handle special case a=0
if a==0
  if b==0                          % c=0 => no solution
    sol = [];
  else                             % b*x+c=0
    sol = -c/b;
  end
else                               % use x=(-b+/-sqrt(b^2-4*a*c))/(2*a)
  d = b^2-4*a*c;
  if d<0                           % solutions are complex
    sol = [];
  elseif d==0                      % only one solution
    sol = -b/(2*a);
  else                             % two real solutions
    sol(1) = (-b-sqrt(d))/(2*a);
    sol(2) = (-b+sqrt(d))/(2*a);
    if sol(1)>sol(2)               % sort solutions
      sol = [sol(2),sol(1)];
    end
  end
  ns = numel(sol);                 % number of solutions
end

end
