summaryrefslogtreecommitdiff
path: root/ext/gmp
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2015-04-16 16:27:42 +0200
committerNikita Popov <nikic@php.net>2015-04-16 16:27:42 +0200
commit7e049b04270b3f46970dcf68b8b2bf12e0c6babd (patch)
treed08dfa6a55ec278d5453892c194f963b1fcdf77f /ext/gmp
parent8e167a2a00175753a26bd812fb4d2c881e68e3db (diff)
downloadphp-git-7e049b04270b3f46970dcf68b8b2bf12e0c6babd.tar.gz
Normalize gmp_remroot() behavior to GMP 5.1
Diffstat (limited to 'ext/gmp')
-rw-r--r--ext/gmp/gmp.c8
-rw-r--r--ext/gmp/tests/gmp_remroot.phpt2
2 files changed, 7 insertions, 3 deletions
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index 12b88c6668..6bc1d3ff16 100644
--- a/ext/gmp/gmp.c
+++ b/ext/gmp/gmp.c
@@ -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);
diff --git a/ext/gmp/tests/gmp_remroot.phpt b/ext/gmp/tests/gmp_remroot.phpt
index 4a3539d87c..331f447aa2 100644
--- a/ext/gmp/tests/gmp_remroot.phpt
+++ b/ext/gmp/tests/gmp_remroot.phpt
@@ -56,7 +56,7 @@ array(2) {
[1]=>
object(GMP)#%d (1) {
["num"]=>
- string(2) "36"
+ string(3) "-36"
}
}
array(2) {