summaryrefslogtreecommitdiff
path: root/ext/gmp
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2015-04-16 16:31:53 +0200
committerNikita Popov <nikic@php.net>2015-04-16 16:31:53 +0200
commitc669aaac71f031724150a04d57d949fb585abecf (patch)
treeab5a040c6e17b23d7557d012f80e89faca4a2ac7 /ext/gmp
parentfeaabd09d092e606b56bf745c6d6d032a7c7c1d7 (diff)
parent25e45a935036d1bc69ed5dda323c09ab1f160d6e (diff)
downloadphp-git-c669aaac71f031724150a04d57d949fb585abecf.tar.gz
Merge branch 'PHP-5.6'
Conflicts: ext/gmp/gmp.c
Diffstat (limited to 'ext/gmp')
-rw-r--r--ext/gmp/gmp.c11
-rw-r--r--ext/gmp/tests/gmp_random_bits.phpt4
-rw-r--r--ext/gmp/tests/gmp_random_range.phpt4
-rw-r--r--ext/gmp/tests/gmp_remroot.phpt2
4 files changed, 16 insertions, 5 deletions
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index f2959a03bc..1994052686 100644
--- a/ext/gmp/gmp.c
+++ b/ext/gmp/gmp.c
@@ -245,6 +245,9 @@ typedef struct _gmp_temp {
#define GMP_MAX_BASE 62
+#define GMP_51_OR_NEWER \
+ ((__GNU_MP_VERSION >= 6) || (__GNU_MP_VERSION >= 5 && __GNU_MP_VERSION_MINOR >= 1))
+
#define IS_GMP(zval) \
(Z_TYPE_P(zval) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zval), gmp_ce))
@@ -1575,7 +1578,15 @@ ZEND_FUNCTION(gmp_rootrem)
add_next_index_zval(return_value, &result1);
add_next_index_zval(return_value, &result2);
+#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, (gmp_ulong) nth);
+#else
+ mpz_root(gmpnum_result1, gmpnum_a, (gmp_ulong) nth);
+ mpz_pow_ui(gmpnum_result2, gmpnum_result1, (gmp_ulong) nth);
+ mpz_sub(gmpnum_result2, gmpnum_a, gmpnum_result2);
+#endif
FREE_GMP_TEMP(temp_a);
}
diff --git a/ext/gmp/tests/gmp_random_bits.phpt b/ext/gmp/tests/gmp_random_bits.phpt
index 21d493cdb6..b4aa5d7b73 100644
--- a/ext/gmp/tests/gmp_random_bits.phpt
+++ b/ext/gmp/tests/gmp_random_bits.phpt
@@ -13,7 +13,7 @@ var_dump(gmp_random_bits(-1));
gmp_random_bits(1);
gmp_random_bits(1024);
-// 2 seconds to make sure the numbers stay in range
+// 0.5 seconds to make sure the numbers stay in range
$start = microtime(true);
$limit = (2 ** 30) - 1;
while (1) {
@@ -26,7 +26,7 @@ while (1) {
}
}
- if (microtime(true) - $start > 2) {
+ if (microtime(true) - $start > 0.5) {
break;
}
}
diff --git a/ext/gmp/tests/gmp_random_range.phpt b/ext/gmp/tests/gmp_random_range.phpt
index a8e7c4a9c1..db2ece61c5 100644
--- a/ext/gmp/tests/gmp_random_range.phpt
+++ b/ext/gmp/tests/gmp_random_range.phpt
@@ -30,7 +30,7 @@ gmp_random_range(-1, $plusTen);
gmp_random_range($zero, $plusTen);
gmp_random_range($minusTen, $plusTen);
-// 2 seconds to make sure the numbers stay in range
+// 0.5 seconds to make sure the numbers stay in range
$start = microtime(true);
while (1) {
for ($i = 0; $i < 5000; $i++) {
@@ -56,7 +56,7 @@ while (1) {
}
}
- if (microtime(true) - $start > 2) {
+ if (microtime(true) - $start > 0.5) {
break;
}
}
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) {