]> www.ginac.de Git - ginac.git/blob - ginac/polynomial/normalize.cpp
Fix most remaining GCC compiler warnings.
[ginac.git] / ginac / polynomial / normalize.cpp
1 /** @file normalize.h
2  *
3  *  Functions to normalize polynomials in a field. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include "normalize.h"
24
25 namespace GiNaC {
26
27 /// Make the univariate polynomial @a a \in F[x] unit normal.
28 /// F should be a field.
29 /// Returns true if the polynomial @x is already unit normal, and false
30 /// otherwise.
31 bool normalize_in_field(umodpoly& a, cln::cl_MI* content_)
32 {
33         if (a.size() == 0)
34                 return true;
35         if (lcoeff(a) == the_one(a[0])) {
36                 if (content_)
37                         *content_ = the_one(a[0]);
38                 return true;
39         }
40
41         const cln::cl_MI lc_1 = recip(lcoeff(a));
42         for (std::size_t k = a.size(); k-- != 0; )
43                 a[k] = a[k]*lc_1;
44         if (content_)
45                 *content_ = lc_1;
46         return false;
47 }
48
49 } // namespace GiNaC