factorial: Fix usage message to fit in with conventions.
[u/mdw/catacomb] / mpbarrett-mexp.c
index 68917aa..0338527 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mpbarrett-mexp.c,v 1.2 2004/04/01 12:50:09 mdw Exp $
+ * $Id$
  *
  * Multiple simultaneous exponentiations
  *
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: mpbarrett-mexp.c,v $
- * Revision 1.2  2004/04/01 12:50:09  mdw
- * Add cyclic group abstraction, with test code.  Separate off exponentation
- * functions for better static linking.  Fix a buttload of bugs on the way.
- * Generally ensure that negative exponents do inversion correctly.  Add
- * table of standard prime-field subgroups.  (Binary field subgroups are
- * currently unimplemented but easy to add if anyone ever finds a good one.)
- *
- * Revision 1.1  2001/06/16 12:58:34  mdw
- * Added simultaneous exponentiation with Barrett reduction.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include "mp.h"
@@ -78,13 +63,10 @@ mp *mpbarrett_mexp(mpbarrett *mb, mp *d, const mp_expfactor *f, size_t n)
   for (i = 0; i < n; i++) {
     if (f[i].exp->f & MP_BURN)
       spare = MP_NEWSEC;
-    if (!(f[i].exp->f & MP_NEG))
+    if (MP_NEGP(f[i].exp))
+      ff[i].base = mp_modinv(MP_NEW, f[i].base, mb->m);
+    else
       ff[i].base = MP_COPY(f[i].base);
-    else {
-      ff[i].base = MP_NEW;
-      mp_gcd(&g, 0, &ff[i].base, mb->m, f[i].base);
-      assert(MP_EQ(g, MP_ONE));
-    }
     ff[i].exp = f[i].exp;
   }
   mp_drop(g);