Standard curves and curve checking.
[u/mdw/catacomb] / mp-sqrt.c
index 98741e8..83880f9 100644 (file)
--- a/mp-sqrt.c
+++ b/mp-sqrt.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mp-sqrt.c,v 1.1 2000/06/22 19:01:44 mdw Exp $
+ * $Id: mp-sqrt.c,v 1.4 2004/03/27 17:54:11 mdw Exp $
  *
  * Compute integer square roots
  *
 /*----- 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.
  *
@@ -68,8 +78,7 @@ mp *mp_sqrt(mp *d, mp *a)
 
   MP_SHRINK(a);
   if (a->v == a->vl) {
-    if (d)
-      mp_drop(d);
+    mp_drop(d);
     return (MP_ZERO);
   }
 
@@ -79,7 +88,6 @@ mp *mp_sqrt(mp *d, mp *a)
   z >>= 1;
   mp_copy(a);
   d = mp_lsr(d, a, z);
-  mp_drop(a);
 
   /* --- Main approximation --- *
    *
@@ -112,9 +120,9 @@ mp *mp_sqrt(mp *d, mp *a)
 
   /* --- Finished, at last --- */
 
+  mp_drop(a);
   mp_drop(q);
-  if (r)
-    mp_drop(r);
+  mp_drop(r);
   return (d);
 }
 
@@ -131,7 +139,7 @@ static int verify(dstr *v)
   mp *q = mp_sqrt(MP_NEW, a);
   int ok = 1;
 
-  if (MP_CMP(q, !=, qq)) {
+  if (!MP_EQ(q, qq)) {
     ok = 0;
     fputs("\n*** sqrt failed", stderr);
     fputs("\n*** a      = ", stderr); mp_writefile(a, stderr, 10);