/*
- poly.cc -- routines for manipulation of polynomials in one var
+ This file is part of LilyPond, the GNU music typesetter.
- (c) 1993--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ Copyright (C) 1993--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ LilyPond is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LilyPond 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
*/
#include "polynomial.hh"
+#include "warn.hh"
+
#include <cmath>
+
+
using namespace std;
/*
Real d = p.eval (x);
if (abs (f) > abs (d) * FUDGE)
- ;
- /*
- warning ("x=%f is not a root of polynomial\n"
- "f (x)=%f, f' (x)=%f \n", x, f, d); */
+ programming_error ("not a root of polynomial\n");
}
void
-Polynomial::check_sols (std::vector<Real> roots) const
+Polynomial::check_sols (vector<Real> roots) const
{
for (vsize i = 0; i < roots.size (); i++)
check_sol (roots[i]);
return !r;
}
-std::vector<Real>
+vector<Real>
Polynomial::solve_cubic ()const
{
- std::vector<Real> sol;
+ vector<Real> sol;
/* normal form: x^3 + Ax^2 + Bx + C = 0 */
Real A = coefs_[2] / coefs_[3];
/*
all roots of quadratic eqn.
*/
-std::vector<Real>
+vector<Real>
Polynomial::solve_quadric ()const
{
- std::vector<Real> sol;
+ vector<Real> sol;
/* normal form: x^2 + px + q = 0 */
Real p = coefs_[1] / (2 * coefs_[2]);
Real q = coefs_[0] / coefs_[2];
}
/* solve linear equation */
-std::vector<Real>
+vector<Real>
Polynomial::solve_linear ()const
{
- std::vector<Real> s;
+ vector<Real> s;
if (coefs_[1])
s.push_back (-coefs_[0] / coefs_[1]);
return s;
}
-std::vector<Real>
+vector<Real>
Polynomial::solve () const
{
Polynomial *me = (Polynomial *) this;
case 3:
return solve_cubic ();
}
- std::vector<Real> s;
+ vector<Real> s;
return s;
}