/*
 * 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_c"
#define MODULE_DESC	"Solve complex cubic equations"
#define MODULE_VER	"0.1"

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

  sl_writeln ("Complex roots of  z^3 + (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_cubic (a, b, c, &z1, &z2, &z3);
  sl_writeln ("");

  switch (nroots)
    {
    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;
      }
    case 3:
      {
	sl_writeln ("three reals roots:");
	sl_complex_writeln_with_message ("z1", z1);
	sl_complex_writeln_with_message ("z2", z2);
	sl_complex_writeln_with_message ("z3", z3);

	break;
      }
    default:
      sl_writeln ("BUG!");
    }

  return SL_SUCCESS;
}

sl_module zsolve_cubic =
  { MODULE_NAME, MODULE_DESC, MODULE_VER, zsolve_c_main };

SL_MODULE_EXPORT (zsolve_cubic);


syntax highlighted by Code2HTML, v. 0.9.1