/*
 * The Spar Library - modular math parser
 * Copyright (C) 2000,2001 Davide Angelocola <davide178@inwind.it>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 *
 */
#define SL_MODULE_BUILTIN
#include <spar/sl_module_devel.h>
#include <spar/sl_io.h>
#include <spar/sl_poly.h>
#include <spar/sl_complex.h>

#define MODULE_NAME     "zsolve_q"
#define MODULE_DESC     "Solve complex quadratic equations"
#define MODULE_VER      "0.1"

int 
zsolve_q_main (void)
{
  double a, b, c;
  sl_complex z1, z2;
  int nroots;

  sl_writeln ("Complex roots of  (a*z^2) + (b*z) + c = 0");
  sl_writeln ("");
  sl_input_double ("input 'a'", &a);
  sl_input_double ("input 'b'", &b);
  sl_input_double ("input 'c'", &c);

  nroots = sl_poly_zsolve_quadratic (a, b, c, &z1, &z2);
  sl_writeln ("");

  switch (nroots)
    {
  
    case 0:
      sl_writeln ("no real roots.");
      break;

    case 1:
      sl_writeln ("one real root:");
      sl_complex_writeln_with_message ("z1", z1);
      break;

    case 2:
      sl_writeln ("two reals roots:");
      sl_complex_writeln_with_message ("z1", z1);
      sl_complex_writeln_with_message ("z2", z2);
      break;
    }

  return SL_SUCCESS;
}

sl_module zsolve_quadratic =
{ MODULE_NAME, MODULE_DESC, MODULE_VER, zsolve_q_main };

SL_MODULE_EXPORT(zsolve_quadratic);


syntax highlighted by Code2HTML, v. 0.9.1