title: Imaginary numbers
body: <p>I have a method that takes 3 <code>double</code>s and calculates the roots via the Quadratic Formula:</p>
  
  <pre><code>public static double[] quadraticFormula(double a, double b, double c) throws ArithmeticException {
      double root1 = 0;
      double root2 = 0;
  
      //sqrt(b^2 - 4ac)
      double discriminant = (b * b) - (4 * a * c);
  
      if (Double.isNaN(discriminant)) {
          throw new ArithmeticException(discriminant + " is not a number!");
      }
  
      if (discriminant &gt; 0) {
          //Two roots
          root1 = (-b + Math.sqrt(discriminant)) / (2 * a);
          root2 = (-b - Math.sqrt(discriminant)) / (2 * a);
      } else if (discriminant == 0) {
          //One root
          root1 = (-b + Math.sqrt(discriminant)) / (2 * a);
      } else if (discriminant &lt; 0) {
          //Imaginary roots
      }
  
      return new double[] { root1, root2 };
  }
  </code></pre>
  
  <p>I want to expand on this and add support for imaginary numbers. How would I accomplish this? My first thought was, in <code>else if (discriminant &lt; 0)</code>, I would get the absolute value of the discriminant and factor the radical. I am going to output the roots to the user, so don't bother with the <em>i</em>, I have a String parser that knows exactly where to put the <em>i</em>. Any ideas on a more efficient method?</p>