-static mp *fadd(field *ff, mp *d, mp *x, mp *y)
-{
- return (mp_add(d, x, y));
+static int fzerop(field *ff, mp *x) { return (!MP_LEN(x)); }
+
+static mp *fneg(field *ff, mp *d, mp *x)
+ { fctx *f = (fctx *)ff; return (mp_sub(d, f->mm.m, 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->mm.m);
+ else if (MP_CMP(d, >, f->mm.m)) d = mp_sub(d, d, f->mm.m);
+ return (d);