clc
clear

function r = raices(p)
  // p is a polynomial
  c = coeff(p, 0)
  b = coeff(p, 1)
  a = coeff(p, 2)
  if (b < 0)
      r(1) = 2*c/(-b + sqrt(b^2 - 4*a*c))
      r(2) = (-b + sqrt(b^2 - 4*a*c))/2/a;
  else
      r(1) = (-b - sqrt(b^2 - 4*a*c))/2/a;
      r(2) = 2*c/(-b - sqrt(b^2 - 4*a*c))
  end
endfunction

p = poly([-1e-7 1e7 1e-7], "x", "c")
roots1 = roots(p)
roots2 = raices(p)

e1 = 1e-8
r1 = roots1(2)
r2 = roots2(2)
disp(r1, r2)

error1 = abs(r1 - e1) / e1
error2 = abs(r2 - e1) / e1

printf("Esperado:\t%e\n", e1)
printf("raices:\t\t%e\t%e\n", r2, error2);
printf("roots:\t\t%e\t%e\n", r1, error1)
