Skip to content

Commit 7e049b0

Browse files
committed
Normalize gmp_remroot() behavior to GMP 5.1
1 parent 8e167a2 commit 7e049b0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

ext/gmp/gmp.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ typedef struct _gmp_temp {
238238
#define GMP_42_OR_NEWER \
239239
((__GNU_MP_VERSION >= 5) || (__GNU_MP_VERSION >= 4 && __GNU_MP_VERSION_MINOR >= 2))
240240

241+
#define GMP_51_OR_NEWER \
242+
((__GNU_MP_VERSION >= 6) || (__GNU_MP_VERSION >= 5 && __GNU_MP_VERSION_MINOR >= 1))
243+
241244
/* The maximum base for input and output conversions is 62 from GMP 4.2
242245
* onwards. */
243246
#if GMP_42_OR_NEWER
@@ -1607,13 +1610,14 @@ ZEND_FUNCTION(gmp_rootrem)
16071610
add_index_zval(return_value, 0, gmp_create(&gmpnum_result1 TSRMLS_CC));
16081611
add_index_zval(return_value, 1, gmp_create(&gmpnum_result2 TSRMLS_CC));
16091612

1610-
#if GMP_42_OR_NEWER
1613+
#if GMP_51_OR_NEWER
1614+
/* mpz_rootrem() is supported since GMP 4.2, but buggy wrt odd roots
1615+
* of negative numbers */
16111616
mpz_rootrem(gmpnum_result1, gmpnum_result2, gmpnum_a, (unsigned long) nth);
16121617
#else
16131618
mpz_root(gmpnum_result1, gmpnum_a, (unsigned long) nth);
16141619
mpz_pow_ui(gmpnum_result2, gmpnum_result1, (unsigned long) nth);
16151620
mpz_sub(gmpnum_result2, gmpnum_a, gmpnum_result2);
1616-
mpz_abs(gmpnum_result2, gmpnum_result2);
16171621
#endif
16181622

16191623
FREE_GMP_TEMP(temp_a);

ext/gmp/tests/gmp_remroot.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ array(2) {
5656
[1]=>
5757
object(GMP)#%d (1) {
5858
["num"]=>
59-
string(2) "36"
59+
string(3) "-36"
6060
}
6161
}
6262
array(2) {

0 commit comments

Comments
 (0)