Permalink
Browse files

Return correct value for nextprime with negative arg on GMP < 4.3

  • Loading branch information...
1 parent cb40b00 commit 9f24053564c38fa4b0bacc101b3fdff6a16bf10e @dvarrazzo committed Apr 22, 2011
Showing with 23 additions and 1 deletion.
  1. +0 −1 src/pmpz_arith.c
  2. +23 −0 src/pmpz_theor.c
View
@@ -66,7 +66,6 @@ PGMP_PG_FUNCTION(pmpz_ ## op) \
PMPZ_UN(neg, PMPZ_NO_CHECK)
PMPZ_UN(abs, PMPZ_NO_CHECK)
PMPZ_UN(sqrt, PMPZ_CHECK_NONEG)
-PMPZ_UN(nextprime, PMPZ_NO_CHECK)
PMPZ_UN(com, PMPZ_NO_CHECK)
View
@@ -39,6 +39,29 @@ PGMP_PG_FUNCTION(pmpz_probab_prime_p)
PG_RETURN_INT32(mpz_probab_prime_p(z1, reps));
}
+PGMP_PG_FUNCTION(pmpz_nextprime)
+{
+ const mpz_t z1;
+ mpz_t zf;
+
+ PGMP_GETARG_MPZ(z1, 0);
+
+ mpz_init(zf);
+
+#if __GMP_MP_RELEASE < 40300
+ if (UNLIKELY(mpz_sgn(z1) < 0)) {
+ mpz_set_ui(zf, 2);
+ }
+ else
+#endif
+ {
+ mpz_nextprime(zf, z1);
+ }
+
+ PGMP_RETURN_MPZ(zf);
+}
+
+
PGMP_PG_FUNCTION(pmpz_gcdext)
{
const mpz_t z1;

0 comments on commit 9f24053

Please sign in to comment.