]> www.ginac.de Git - ginac.git/blobdiff - ginac/factor.cpp
Update copyright statements.
[ginac.git] / ginac / factor.cpp
index 945b25e653a4c56ba59b1ec3abeac50f34a065f8..0f17e2410185cc373e492e6481eb7300e8b6c6be 100644 (file)
@@ -33,7 +33,7 @@
  */
 
 /*
- *  GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2014 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
@@ -1509,7 +1509,17 @@ static ex factor_univariate(const ex& poly, const ex& x, unsigned int& prime)
        cl_modint_ring R;
        unsigned int trials = 0;
        unsigned int minfactors = 0;
-       cl_I lc = lcoeff(prim) * the<cl_I>(ex_to<numeric>(cont).to_cl_N());
+
+       const numeric& cont_n = ex_to<numeric>(cont);
+       cl_I i_cont;
+       if (cont_n.is_integer()) {
+               i_cont = the<cl_I>(cont_n.to_cl_N());
+       } else {
+               // poly \in Q[x] => poly = q ipoly, ipoly \in Z[x], q \in Q
+               // factor(poly) \equiv q factor(ipoly)
+               i_cont = cl_I(1);
+       }
+       cl_I lc = lcoeff(prim)*i_cont;
        upvec factors;
        while ( trials < 2 ) {
                umodpoly modpoly;
@@ -2108,8 +2118,9 @@ static ex put_factors_into_lst(const ex& e)
                return result;
        }
        if ( is_a<symbol>(e) || is_a<add>(e) ) {
-               result.append(1);
-               result.append(e);
+               ex icont(e.integer_content());
+               result.append(icont);
+               result.append(e/icont);
                return result;
        }
        if ( is_a<mul>(e) ) {