#define GMP_42_OR_NEWER \
((__GNU_MP_VERSION >= 5) || (__GNU_MP_VERSION >= 4 && __GNU_MP_VERSION_MINOR >= 2))
+#define GMP_51_OR_NEWER \
+ ((__GNU_MP_VERSION >= 6) || (__GNU_MP_VERSION >= 5 && __GNU_MP_VERSION_MINOR >= 1))
+
/* The maximum base for input and output conversions is 62 from GMP 4.2
* onwards. */
#if GMP_42_OR_NEWER
add_index_zval(return_value, 0, gmp_create(&gmpnum_result1 TSRMLS_CC));
add_index_zval(return_value, 1, gmp_create(&gmpnum_result2 TSRMLS_CC));
-#if GMP_42_OR_NEWER
+#if GMP_51_OR_NEWER
+ /* mpz_rootrem() is supported since GMP 4.2, but buggy wrt odd roots
+ * of negative numbers */
mpz_rootrem(gmpnum_result1, gmpnum_result2, gmpnum_a, (unsigned long) nth);
#else
mpz_root(gmpnum_result1, gmpnum_a, (unsigned long) nth);
mpz_pow_ui(gmpnum_result2, gmpnum_result1, (unsigned long) nth);
mpz_sub(gmpnum_result2, gmpnum_a, gmpnum_result2);
- mpz_abs(gmpnum_result2, gmpnum_result2);
#endif
FREE_GMP_TEMP(temp_a);