Rename MP_IS* to MP_*P, for consistency's sake. Use these macros more often.
[u/mdw/catacomb] / gfreduce.c
index ae31d5c..bdf3579 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: gfreduce.c,v 1.5 2004/04/08 01:36:15 mdw Exp $
+ * $Id$
  *
  * Efficient reduction modulo sparse binary polynomials
  *
@@ -338,7 +338,7 @@ int gfreduce_trace(gfreduce *r, mp *x)
     y = gfreduce_do(r, t, t);
     y = gf_add(y, y, x);
   }
-  rc = !MP_ISZERO(y);
+  rc = !MP_ZEROP(y);
   mp_drop(spare);
   mp_drop(y);
   return (rc);
@@ -410,7 +410,7 @@ mp *gfreduce_quadsolve(gfreduce *r, mp *d, mp *x)
        z = gf_add(z, z, t);
        w = gf_add(w, w, rho);
       }
-      if (!MP_ISZERO(w))
+      if (!MP_ZEROP(w))
        break;
       MP_DROP(z);
       MP_DROP(w);
@@ -450,13 +450,19 @@ mp *gfreduce_exp(gfreduce *gr, mp *d, mp *a, mp *e)
   mp *spare = (e->f & MP_BURN) ? MP_NEWSEC : MP_NEW;
 
   MP_SHRINK(e);
-  if (!MP_LEN(e))
+  MP_COPY(a);
+  if (MP_ZEROP(e))
     ;
-  else if (MP_LEN(e) < EXP_THRESH)
-    EXP_SIMPLE(x, a, e);
-  else
-    EXP_WINDOW(x, a, e);
+  else {
+    if (MP_NEGP(e))
+      a = gf_modinv(a, a, gr->p);
+    if (MP_LEN(e) < EXP_THRESH)
+      EXP_SIMPLE(x, a, e);
+    else
+      EXP_WINDOW(x, a, e);
+  }
   mp_drop(d);
+  mp_drop(a);
   mp_drop(spare);
   return (x);
 }