Normalize gmp_remroot() behavior to GMP 5.1

This commit is contained in:
Nikita Popov 2015-04-16 16:27:42 +02:00
parent 8e167a2a00
commit 7e049b0427
2 changed files with 7 additions and 3 deletions

View File

@ -238,6 +238,9 @@ typedef struct _gmp_temp {
#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
@ -1607,13 +1610,14 @@ ZEND_FUNCTION(gmp_rootrem)
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);

View File

@ -56,7 +56,7 @@ array(2) {
[1]=>
object(GMP)#%d (1) {
["num"]=>
string(2) "36"
string(3) "-36"
}
}
array(2) {