X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/432c4e184d44704511a5991b80224a87cb1d4613..298182ad446aaced14dea7ed0e7c968946787288:/mp-sqrt.c diff --git a/mp-sqrt.c b/mp-sqrt.c index 83880f9..2e35158 100644 --- a/mp-sqrt.c +++ b/mp-sqrt.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: mp-sqrt.c,v 1.4 2004/03/27 17:54:11 mdw Exp $ + * $Id$ * * Compute integer square roots * @@ -27,24 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: mp-sqrt.c,v $ - * Revision 1.4 2004/03/27 17:54:11 mdw - * Standard curves and curve checking. - * - * Revision 1.3 2001/02/03 12:00:29 mdw - * Now @mp_drop@ checks its argument is non-NULL before attempting to free - * it. Note that the macro version @MP_DROP@ doesn't do this. - * - * Revision 1.2 2000/10/08 12:02:21 mdw - * Use @MP_EQ@ instead of @MP_CMP@. - * - * Revision 1.1 2000/06/22 19:01:44 mdw - * Compute (approximations to) integer square roots. - * - */ - /*----- Header files ------------------------------------------------------*/ #include "mp.h" @@ -72,12 +54,12 @@ mp *mp_sqrt(mp *d, mp *a) /* --- Sanity preservation --- */ - assert(((void)"imaginary root in mp_sqrt", !(a->f & MP_NEG))); + assert(!MP_NEGP(a)); /* --- Deal with trivial cases --- */ MP_SHRINK(a); - if (a->v == a->vl) { + if (MP_ZEROP(a)) { mp_drop(d); return (MP_ZERO); } @@ -102,12 +84,12 @@ mp *mp_sqrt(mp *d, mp *a) for (;;) { q = mp_sqr(q, d); q = mp_sub(q, q, a); - if (q->v == q->vl) + if (MP_ZEROP(q)) break; - if (q->f & MP_NEG) { + if (MP_NEGP(q)) { r = mp_lsl(r, d, 1); r->f |= MP_NEG; - if (MP_CMP(q, <=, r)) + if (MP_CMP(q, >=, r)) break; } mp_div(&r, &q, q, d);