/*
* 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>
#define MODULE_NAME "solve_c"
#define MODULE_DESC "Solve cubic equations"
#define MODULE_VER "0.1"
int
solve_c_main (void)
{
double a, b, c;
double x1, x2, x3;
int nroots;
sl_writeln ("Real roots of x^3 + (a*x^2) + (b*x) + 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_solve_cubic (a, b, c, &x1, &x2, &x3);
sl_writeln ("");
switch (nroots)
{
case 1:
{
sl_writeln ("one real root:");
sl_write_value_with_label ("x1", x1);
break;
}
case 2:
{
sl_writeln ("two reals roots:");
sl_write_value_with_label ("x1", x1);
sl_write_value_with_label ("x2", x2);
break;
}
case 3:
{
sl_writeln ("three reals roots:");
sl_write_value_with_label ("x1", x1);
sl_write_value_with_label ("x2", x2);
sl_write_value_with_label ("x3", x3);
break;
}
default:
sl_writeln ("BUG!");
}
return SL_SUCCESS;
}
sl_module solve_cubic =
{ MODULE_NAME, MODULE_DESC, MODULE_VER, solve_c_main };
SL_MODULE_EXPORT (solve_cubic);
syntax highlighted by Code2HTML, v. 0.9.1