// roots.cc
// Implemantation of API for finding roots of polynomials

#include <cmath>

// roots(a, b, c, r1, r2) - returns the number of 
// real roots of ax^2 + bx + c. If two roots exists
// they are returned is r1 and r2. If only one root
// exists, it is returned in r1. Otherwise the value
// of r1 and r2 is undetermined.

int roots(float a, float b, float c, 
          float& r1, float& r2)
{
  float d = b * b - 4.0 * a * c;
  if (d < 0) { 
    return 0;
  }
  r1 = (-b + sqrt(d)) / (2.0 * a);
  if (d == 0) {
    return 1;
  }
  r2 = (-b - sqrt(d)) / (2.0 * a);
  return 2;
}
