X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/f4535c6454395e6d56ce0091a07b6d4f7d54a47f..e564e3f84ad0ea42b78559c0bfe304893fd5e76b:/f-niceprime.c diff --git a/f-niceprime.c b/f-niceprime.c index ce96977..83b9ca5 100644 --- a/f-niceprime.c +++ b/f-niceprime.c @@ -7,7 +7,7 @@ * (c) 2004 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,12 +15,12 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, @@ -99,20 +99,20 @@ static mp *fsqrt(field *ff, mp *d, mp *x) { static mp *fdbl(field *ff, mp *d, mp *x) { fctx_niceprime *f = (fctx_niceprime *)ff; d = mp_lsl(d, x, 1); - if (MP_CMP(d, >, f->r.p)) d = mp_sub(d, d, f->r.p); + if (MP_CMP(d, >=, f->r.p)) d = mp_sub(d, d, f->r.p); return (d); } static mp *ftpl(field *ff, mp *d, mp *x) { fctx_niceprime *f = (fctx_niceprime *)ff; MP_DEST(d, MP_LEN(x) + 1, x->f); - MPX_UMULN(d->v, d->vl, x->v, x->vl, 3); - while (MP_CMP(d, >, f->r.p)) d = mp_sub(d, d, f->r.p); + MPX_UMULN(d->v, d->vl, x->v, x->vl, 3); d->f &= ~MP_UNDEF; + while (MP_CMP(d, >=, f->r.p)) d = mp_sub(d, d, f->r.p); return (d); } static mp *fqdl(field *ff, mp *d, mp *x) { fctx_niceprime *f = (fctx_niceprime *)ff; d = mp_lsl(d, x, 2); - while (MP_CMP(d, >, f->r.p)) d = mp_sub(d, d, f->r.p); + while (MP_CMP(d, >=, f->r.p)) d = mp_sub(d, d, f->r.p); return (d); } @@ -157,6 +157,7 @@ field *field_niceprime(mp *p) return (0); } f->f.m = f->r.p; + f->f.q = f->r.p; return (&f->f); }