math/mp-sqrt.c, math/pgen-granfrob.c: Publish `squarep' function.
[catacomb] / math / pgen-granfrob.c
index 98c8f8c..0516539 100644 (file)
 
 /*----- Main code ---------------------------------------------------------*/
 
-static int squarep(mp *n)
-{
-  mp *t = MP_NEW;
-  int rc;
-
-  if (MP_NEGP(n)) return (0);
-  t = mp_sqrt(t, n); t = mp_sqr(t, t);
-  rc = MP_EQ(t, n); mp_drop(t); return (rc);
-}
-
 /* --- @pgen_granfrob@ --- *
  *
  * Arguments:  @mp *n@ = an integer to test
@@ -103,7 +93,7 @@ int pgen_granfrob(mp *n, int a, int b)
     e = mp_jacobi(&md, n);
 
     /* If %$\Delta$% is a perfect square then the test can't work. */
-    if (e == 1 && squarep(&md)) { rc = PGEN_ABORT; goto end; }
+    if (e == 1 && mp_squarep(&md)) { rc = PGEN_ABORT; goto end; }
   } else {
     /* Determine parameters.  Use Selfridge's `Method A': choose the first
      * %$\Delta$% from the sequence %$5$%, %$-7$%, %%\dots%%, such that
@@ -113,7 +103,7 @@ int pgen_granfrob(mp *n, int a, int b)
     wa = 1; wd = 5;
     for (;;) {
       e = mp_jacobi(&md, n); if (e != +1) break;
-      if (wd == 25 && squarep(n)) { rc = PGEN_FAIL; goto end; }
+      if (wd == 25 && mp_squarep(n)) { rc = PGEN_FAIL; goto end; }
       wd += 2; md.f ^= MP_NEG;
     }
     a = 1; d = wd;