From: Richard Kreckel Date: Tue, 3 Nov 2015 19:53:07 +0000 (+0100) Subject: Fix most remaining GCC compiler warnings. X-Git-Tag: release_1-7-0~7^2~68 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=faf8c206bdcd01eee758103d56b83a634f787e7a Fix most remaining GCC compiler warnings. --- diff --git a/check/exam_inifcns_nstdsums.cpp b/check/exam_inifcns_nstdsums.cpp index c93d0b4a..9415b9b3 100644 --- a/check/exam_inifcns_nstdsums.cpp +++ b/check/exam_inifcns_nstdsums.cpp @@ -287,6 +287,8 @@ static unsigned inifcns_test_LiG() cout << "." << flush; } + Digits = digitsbuf; + return result; } @@ -300,6 +302,7 @@ static unsigned inifcns_test_LiG() static unsigned inifcns_test_legacy() { + int digitsbuf = Digits; Digits = 17; ex prec = 5 * pow(10, -(ex)Digits); @@ -362,6 +365,8 @@ static unsigned inifcns_test_legacy() result++; } + Digits = digitsbuf; + return result; } diff --git a/ginac/Makefile.am b/ginac/Makefile.am index 49bd59a5..4c83ffd4 100644 --- a/ginac/Makefile.am +++ b/ginac/Makefile.am @@ -21,7 +21,9 @@ libginac_la_SOURCES = add.cpp archive.cpp basic.cpp clifford.cpp color.cpp \ polynomial/mod_gcd.cpp \ polynomial/cra_garner.cpp \ polynomial/gcd_euclid.h \ +polynomial/remainder.cpp \ polynomial/remainder.h \ +polynomial/normalize.cpp \ polynomial/normalize.h \ polynomial/upoly.h \ polynomial/ring_traits.h \ diff --git a/ginac/function.cppy b/ginac/function.cppy index 4f0c6cfc..0a521e11 100644 --- a/ginac/function.cppy +++ b/ginac/function.cppy @@ -732,22 +732,22 @@ ex function::pderivative(unsigned diff_param) const // partial differentiation GINAC_ASSERT(serialsetflag(status_flags::dynallocated | - status_flags::evaluated); - - current_serial = serial; - if (opt.power_use_exvector_args) - return ((power_funcp_exvector)(opt.power_f))(seq, power_param); - switch (opt.nparams) { - // the following lines have been generated for max. @maxargs@ parameters + if (opt.power_f) { + // Invoke the defined power function. + current_serial = serial; + if (opt.power_use_exvector_args) + return ((power_funcp_exvector)(opt.power_f))(seq, power_param); + switch (opt.nparams) { + // the following lines have been generated for max. @maxargs@ parameters +++ for N in range(1, maxargs + 1): - case @N@: - return ((power_funcp_@N@)(opt.power_f))(@seq('seq[%(n)d]', N, 0)@, power_param); + case @N@: + return ((power_funcp_@N@)(opt.power_f))(@seq('seq[%(n)d]', N, 0)@, power_param); --- - // end of generated lines + // end of generated lines + } } - throw(std::logic_error("function::power(): no power function defined")); + // No power function defined? Fall back to returning a power object. + return (new GiNaC::power(*this, power_param))->setflag(status_flags::dynallocated | + status_flags::evaluated); } ex function::expand(unsigned options) const @@ -800,27 +802,25 @@ ex function::expand(unsigned options) const GINAC_ASSERT(serial & function::registered_functions() diff --git a/ginac/normal.cpp b/ginac/normal.cpp index e0920b36..c6dc39e6 100644 --- a/ginac/normal.cpp +++ b/ginac/normal.cpp @@ -120,6 +120,11 @@ static bool get_first_symbol(const ex &e, ex &x) * * @see get_symbol_stats */ struct sym_desc { + /** Initialize symbol, leave other variables uninitialized */ + sym_desc(const ex& s) + : sym(s), deg_a(0), deg_b(0), ldeg_a(0), ldeg_b(0), max_deg(0), max_lcnops(0) + { } + /** Reference to symbol */ ex sym; @@ -161,9 +166,7 @@ static void add_symbol(const ex &s, sym_desc_vec &v) if (it.sym.is_equal(s)) // If it's already in there, don't add it a second time return; - sym_desc d; - d.sym = s; - v.push_back(d); + v.push_back(sym_desc(s)); } // Collect all symbols of an expression (used internally by get_symbol_stats()) diff --git a/ginac/polynomial/normalize.cpp b/ginac/polynomial/normalize.cpp new file mode 100644 index 00000000..4292bbc9 --- /dev/null +++ b/ginac/polynomial/normalize.cpp @@ -0,0 +1,49 @@ +/** @file normalize.h + * + * Functions to normalize polynomials in a field. */ + +/* + * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "normalize.h" + +namespace GiNaC { + +/// Make the univariate polynomial @a a \in F[x] unit normal. +/// F should be a field. +/// Returns true if the polynomial @x is already unit normal, and false +/// otherwise. +bool normalize_in_field(umodpoly& a, cln::cl_MI* content_) +{ + if (a.size() == 0) + return true; + if (lcoeff(a) == the_one(a[0])) { + if (content_) + *content_ = the_one(a[0]); + return true; + } + + const cln::cl_MI lc_1 = recip(lcoeff(a)); + for (std::size_t k = a.size(); k-- != 0; ) + a[k] = a[k]*lc_1; + if (content_) + *content_ = lc_1; + return false; +} + +} // namespace GiNaC diff --git a/ginac/polynomial/normalize.h b/ginac/polynomial/normalize.h index 27605d05..280e5983 100644 --- a/ginac/polynomial/normalize.h +++ b/ginac/polynomial/normalize.h @@ -29,27 +29,7 @@ namespace GiNaC { -/// Make the univariate polynomial @a a \in F[x] unit normal. -/// F should be a field. -/// Returns true if the polynomial @x is already unit normal, and false -/// otherwise. -static bool normalize_in_field(umodpoly& a, cln::cl_MI* content_ = 0) -{ - if (a.size() == 0) - return true; - if (lcoeff(a) == the_one(a[0])) { - if (content_) - *content_ = the_one(a[0]); - return true; - } - - const cln::cl_MI lc_1 = recip(lcoeff(a)); - for (std::size_t k = a.size(); k-- != 0; ) - a[k] = a[k]*lc_1; - if (content_) - *content_ = lc_1; - return false; -} +bool normalize_in_field(umodpoly& a, cln::cl_MI* content_ = 0); /// Make the univariate polynomial @a x unit normal. This version is used /// for rings which are not fields. diff --git a/ginac/polynomial/optimal_vars_finder.cpp b/ginac/polynomial/optimal_vars_finder.cpp index 09b9590b..2be7318a 100644 --- a/ginac/polynomial/optimal_vars_finder.cpp +++ b/ginac/polynomial/optimal_vars_finder.cpp @@ -46,6 +46,11 @@ namespace { * @see get_symbol_stats */ struct sym_desc { + /** Initialize symbol, leave other variables uninitialized */ + sym_desc(const ex& s) + : sym(s), deg_a(0), deg_b(0), ldeg_a(0), ldeg_b(0), max_deg(0), max_lcnops(0) + { } + /** Reference to symbol */ ex sym; @@ -87,9 +92,7 @@ static void add_symbol(const ex &s, sym_desc_vec &v) if (it.sym.is_equal(s)) // If it's already in there, don't add it a second time return; } - sym_desc d; - d.sym = s; - v.push_back(d); + v.push_back(sym_desc(s)); } // Collect all symbols of an expression (used internally by get_symbol_stats()) diff --git a/ginac/polynomial/remainder.cpp b/ginac/polynomial/remainder.cpp new file mode 100644 index 00000000..3f29e825 --- /dev/null +++ b/ginac/polynomial/remainder.cpp @@ -0,0 +1,87 @@ +/** @file remainder.h + * + * Functions calculating remainders. */ + +/* + * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "remainder.h" +#include "ring_traits.h" +#include "upoly_io.h" +#include "debug.h" + +namespace GiNaC { + +/** + * @brief Polynomial remainder for univariate polynomials over fields + * + * Given two univariate polynomials \f$a, b \in F[x]\f$, where F is + * a finite field (presumably Z/p) computes the remainder @a r, which is + * defined as \f$a = b q + r\f$. Returns true if the remainder is zero + * and false otherwise. + */ +bool +remainder_in_field(umodpoly& r, const umodpoly& a, const umodpoly& b) +{ + typedef cln::cl_MI field_t; + + if (degree(a) < degree(b)) { + r = a; + return false; + } + // The coefficient ring is a field, so any 0 degree polynomial + // divides any other polynomial. + if (degree(b) == 0) { + r.clear(); + return true; + } + + r = a; + const field_t b_lcoeff = lcoeff(b); + for (std::size_t k = a.size(); k-- >= b.size(); ) { + + // r -= r_k/b_n x^{k - n} b(x) + if (zerop(r[k])) + continue; + + field_t qk = div(r[k], b_lcoeff); + bug_on(zerop(qk), "division in a field yield zero: " + << r[k] << '/' << b_lcoeff); + + // Why C++ is so off-by-one prone? + for (std::size_t j = k, i = b.size(); i-- != 0; --j) { + if (zerop(b[i])) + continue; + r[j] = r[j] - qk*b[i]; + } + bug_on(!zerop(r[k]), "polynomial division in field failed: " << + "r[" << k << "] = " << r[k] << ", " << + "r = " << r << ", b = " << b); + + } + + // Canonicalize the remainder: remove leading zeros. Give a hint + // to canonicalize(): we know degree(remainder) < degree(b) + // (because the coefficient ring is a field), so + // c_{degree(b)} \ldots c_{degree(a)} are definitely zero. + std::size_t from = degree(b) - 1; + canonicalize(r, from); + return r.empty(); +} + +} // namespace GiNaC diff --git a/ginac/polynomial/remainder.h b/ginac/polynomial/remainder.h index a53c482e..a3f9ae8e 100644 --- a/ginac/polynomial/remainder.h +++ b/ginac/polynomial/remainder.h @@ -30,62 +30,7 @@ namespace GiNaC { -/** - * @brief Polynomial remainder for univariate polynomials over fields - * - * Given two univariate polynomials \f$a, b \in F[x]\f$, where F is - * a finite field (presumably Z/p) computes the remainder @a r, which is - * defined as \f$a = b q + r\f$. Returns true if the remainder is zero - * and false otherwise. - */ -static bool -remainder_in_field(umodpoly& r, const umodpoly& a, const umodpoly& b) -{ - typedef cln::cl_MI field_t; - - if (degree(a) < degree(b)) { - r = a; - return false; - } - // The coefficient ring is a field, so any 0 degree polynomial - // divides any other polynomial. - if (degree(b) == 0) { - r.clear(); - return true; - } - - r = a; - const field_t b_lcoeff = lcoeff(b); - for (std::size_t k = a.size(); k-- >= b.size(); ) { - - // r -= r_k/b_n x^{k - n} b(x) - if (zerop(r[k])) - continue; - - field_t qk = div(r[k], b_lcoeff); - bug_on(zerop(qk), "division in a field yield zero: " - << r[k] << '/' << b_lcoeff); - - // Why C++ is so off-by-one prone? - for (std::size_t j = k, i = b.size(); i-- != 0; --j) { - if (zerop(b[i])) - continue; - r[j] = r[j] - qk*b[i]; - } - bug_on(!zerop(r[k]), "polynomial division in field failed: " << - "r[" << k << "] = " << r[k] << ", " << - "r = " << r << ", b = " << b); - - } - - // Canonicalize the remainder: remove leading zeros. Give a hint - // to canonicalize(): we know degree(remainder) < degree(b) - // (because the coefficient ring is a field), so - // c_{degree(b)} \ldots c_{degree(a)} are definitely zero. - std::size_t from = degree(b) - 1; - canonicalize(r, from); - return r.empty(); -} +bool remainder_in_field(umodpoly& r, const umodpoly& a, const umodpoly& b); /** * @brief Polynomial remainder for univariate polynomials over a ring. diff --git a/ginac/polynomial/upoly.h b/ginac/polynomial/upoly.h index 17925b6b..f554d602 100644 --- a/ginac/polynomial/upoly.h +++ b/ginac/polynomial/upoly.h @@ -169,7 +169,7 @@ template bool divide(T& p, const typename T::value_type& c) // Convert Z[x] -> Z/p[x] -static void +static inline void make_umodpoly(umodpoly& up, const upoly& p, const cln::cl_modint_ring& R) { for (std::size_t i = p.size(); i-- != 0; ) diff --git a/ginsh/ginsh_lexer.lpp b/ginsh/ginsh_lexer.lpp index a3824cd2..b33763b3 100644 --- a/ginsh/ginsh_lexer.lpp +++ b/ginsh/ginsh_lexer.lpp @@ -26,6 +26,8 @@ * Definitions */ +%option nounput + %pointer %{