Skip to content

Commit ecbb154

Browse files
author
jkuipers
committed
Bugfix in polynomial division of non-monic univariate polynomials that
results in a quotient of zero.
1 parent fc74755 commit ecbb154

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

sources/polywrap.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ WORD *poly_divmod(PHEAD WORD *a, WORD *b, int divmod) {
212212
int denompower = 0;
213213

214214
if (!lcoeffb.is_one()) {
215-
215+
216216
if (AN.poly_num_vars > 2) {
217217
// the original polynomial is multivariate (one dummy variable has
218218
// been added), so it is not trivial to determine which power of
@@ -231,6 +231,7 @@ WORD *poly_divmod(PHEAD WORD *a, WORD *b, int divmod) {
231231

232232
// divide and determine the power
233233
poly ppow(pa/pb);
234+
cout << pa << " / " << pb << " = " << ppow << endl;
234235
for (int i=1; i<ppow[0]; i+=ppow[i])
235236
denompower = max(denompower, DENOMPOWER - ppow[i+AN.poly_num_vars]);
236237

@@ -241,9 +242,9 @@ WORD *poly_divmod(PHEAD WORD *a, WORD *b, int divmod) {
241242
else {
242243
// one variable, so the power is the difference of the degrees
243244

244-
denompower = pa.degree(0) - pb.degree(0) + 1;
245+
denompower = MaX(0, pa.degree(0) - pb.degree(0) + 1);
245246
}
246-
247+
247248
// multiply a by that power
248249
WORD n = lcoeffb[lcoeffb[1]];
249250
RaisPow(BHEAD (UWORD *)&lcoeffb[2+AN.poly_num_vars], &n, denompower);

0 commit comments

Comments
 (0)