Rename MP_IS* to MP_*P, for consistency's sake. Use these macros more often.
[u/mdw/catacomb] / f-niceprime.c
index 8645cb6..d9ec1ac 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: f-niceprime.c,v 1.6 2004/04/08 01:36:15 mdw Exp $
+ * $Id$
  *
  * Prime fields with efficient reduction for special-form primes
  *
@@ -50,21 +50,21 @@ static void fdestroy(field *ff)
 static mp *frand(field *ff, mp *d, grand *r)
   { fctx *f = (fctx *)ff; return (mprand_range(d, f->r.p, r, 0)); }
 
-static int fzerop(field *ff, mp *x) { return (!MP_LEN(x)); }
+static int fzerop(field *ff, mp *x) { return (MP_ZEROP(x)); }
 
 static mp *fneg(field *ff, mp *d, mp *x)
   { fctx *f = (fctx *)ff; return (mp_sub(d, f->r.p, x)); }
 
 static mp *fadd(field *ff, mp *d, mp *x, mp *y) {
   fctx *f = (fctx *)ff; d = mp_add(d, x, y);
-  if (d->f & MP_NEG) d = mp_add(d, d, f->r.p);
+  if (MP_NEGP(d)) d = mp_add(d, d, f->r.p);
   else if (MP_CMP(d, >, f->r.p)) d = mp_sub(d, d, f->r.p);
   return (d);
 }
 
 static mp *fsub(field *ff, mp *d, mp *x, mp *y) {
   fctx *f = (fctx *)ff; d = mp_sub(d, x, y);
-  if (d->f & MP_NEG) d = mp_add(d, d, f->r.p);
+  if (MP_NEGP(d)) d = mp_add(d, d, f->r.p);
   else if (MP_CMP(d, >, f->r.p)) d = mp_sub(d, d, f->r.p);
   return (d);
 }
@@ -109,7 +109,7 @@ static mp *fqdl(field *ff, mp *d, mp *x) {
 
 static mp *fhlv(field *ff, mp *d, mp *x) {
   fctx *f = (fctx *)ff;
-  if (!MP_LEN(x)) { MP_COPY(x); MP_DROP(d); return (x); }
+  if (MP_ZEROP(x)) { MP_COPY(x); MP_DROP(d); return (x); }
   if (x->v[0] & 1) { d = mp_add(d, x, f->r.p); x = d; }
   return (mp_lsr(d, x, 1));
 }