Skip to content
Browse files

Guard divisible/congruent for 0 input on GMP < 4.2

Return the same results of GMP >= 4.2.
  • Loading branch information...
1 parent 90fb24a commit cb40b00a6a5b628a5ae4f7a922edc0b15cc47295 @dvarrazzo committed Apr 22, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 src/pmpz_arith.c
View
15 src/pmpz_arith.c
@@ -288,6 +288,13 @@ PGMP_PG_FUNCTION(pmpz_divisible)
PGMP_GETARG_MPZ(n, 0);
PGMP_GETARG_MPZ(d, 1);
+ /* GMP 4.1 doesn't guard for zero */
+#if __GMP_MP_RELEASE < 40200
+ if (UNLIKELY(MPZ_IS_ZERO(d))) {
+ PG_RETURN_BOOL(MPZ_IS_ZERO(n));
+ }
+#endif
+
PG_RETURN_BOOL(mpz_divisible_p(n, d));
}
@@ -312,6 +319,14 @@ PGMP_PG_FUNCTION(pmpz_congruent)
PGMP_GETARG_MPZ(c, 1);
PGMP_GETARG_MPZ(d, 2);
+ /* GMP 4.1 doesn't guard for zero */
+#if __GMP_MP_RELEASE < 40200
+ if (UNLIKELY(MPZ_IS_ZERO(d))) {
+ PG_RETURN_BOOL(0 == mpz_cmp(n, c));
+ }
+#endif
+
+
PG_RETURN_BOOL(mpz_congruent_p(n, c, d));
}

0 comments on commit cb40b00

Please sign in to comment.
Something went wrong with that request. Please try again.