]> www.ginac.de Git - ginac.git/blobdiff - ginac/polynomial/mgcd.cpp
Fix warning "control reaches end of non-void function".
[ginac.git] / ginac / polynomial / mgcd.cpp
index 24da934690237e42e26a97caa35b09080eabc672..9eb535aff1dfad2e53e4e89e59a3bbaec5e8a930 100644 (file)
@@ -3,7 +3,7 @@
  *  Chinese remainder algorithm. */
 
 /*
  *  Chinese remainder algorithm. */
 
 /*
- *  GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2011 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
  *
  *  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
@@ -30,6 +30,9 @@
 #include <numeric> // std::accumulate
 
 #include <cln/integer.h>
 #include <numeric> // std::accumulate
 
 #include <cln/integer.h>
+#include <cln/integer_ring.h>
+#include <cln/rational.h>
+#include <cln/rational_ring.h>
 
 namespace GiNaC {
 
 
 namespace GiNaC {
 
@@ -37,12 +40,20 @@ static cln::cl_I extract_integer_content(ex& Apr, const ex& A)
 {
        static const cln::cl_I n1(1);
        const numeric icont_ = A.integer_content();
 {
        static const cln::cl_I n1(1);
        const numeric icont_ = A.integer_content();
-       const cln::cl_I icont = cln::the<cln::cl_I>(icont_.to_cl_N());
-       if (icont != 1) {
-               Apr = (A/icont_).expand();
-               return icont;
+       GINAC_ASSERT(cln::instanceof(icont_.to_cl_N(), cln::cl_RA_ring));
+       if (cln::instanceof(icont_.to_cl_N(), cln::cl_I_ring)) {
+               const cln::cl_I icont = cln::the<cln::cl_I>(icont_.to_cl_N());
+               if (icont != 1) {
+                       Apr = (A/icont_).expand();
+                       return icont;
+               } else {
+                       Apr = A;
+                       return n1;
+               }
        } else {
        } else {
-               Apr = A;
+               Apr = (A/icont_).expand();
+               // A is a polynomail over rationals, so GCD is defined
+               // up to arbitrary rational number.
                return n1;
        }
 }
                return n1;
        }
 }
@@ -89,7 +100,7 @@ ex chinrem_gcd(const ex& A_, const ex& B_, const exvector& vars)
                Cp = (Cp*numeric(nlc)).expand().smod(pnum);
                exp_vector_t cp_deg = degree_vector(Cp, vars);
                if (zerop(cp_deg))
                Cp = (Cp*numeric(nlc)).expand().smod(pnum);
                exp_vector_t cp_deg = degree_vector(Cp, vars);
                if (zerop(cp_deg))
-                       return numeric(g_lc);
+                       return numeric(c);
                if (zerop(q)) {
                        H = Cp;
                        n = cp_deg;
                if (zerop(q)) {
                        H = Cp;
                        n = cp_deg;