return (d);
}
+/* --- @mp_squarep@ --- *
+ *
+ * Arguments: @mp *n@ = an integer
+ *
+ * Returns: Nonzero if and only if @n@ is a perfect square, i.e.,
+ * %$n = a^2$% for some rational integer %$a$%.
+ */
+
+int mp_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);
+}
+
/*----- Test rig ----------------------------------------------------------*/
#ifdef TEST_RIG
extern mp *mp_sqrt(mp */*d*/, mp */*a*/);
+/* --- @mp_squarep@ --- *
+ *
+ * Arguments: @mp *n@ = an integer
+ *
+ * Returns: Nonzero if and only if @n@ is a perfect square, i.e.,
+ * %$n = a^2$% for some rational integer %$a$%.
+ */
+
+extern int mp_squarep(mp */*n*/);
+
/* --- @mp_nthrt@ --- *
*
* Arguments: @mp *d@ = fake destination
/*----- 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
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
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;