]> granicus.if.org Git - php/commitdiff
Normalize gmp_remroot() behavior to GMP 5.1
authorNikita Popov <nikic@php.net>
Thu, 16 Apr 2015 14:27:42 +0000 (16:27 +0200)
committerNikita Popov <nikic@php.net>
Thu, 16 Apr 2015 14:27:42 +0000 (16:27 +0200)
ext/gmp/gmp.c
ext/gmp/tests/gmp_remroot.phpt

index 12b88c66688b10daa62c809626dbc6978a65965b..6bc1d3ff16895e7a6604dbdf37976eeb41541901 100644 (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);
index 4a3539d87cb436ae4804fe958832bec413c61428..331f447aa2070b92fcfaf6b99379680467cc95a9 100644 (file)
@@ -56,7 +56,7 @@ array(2) {
   [1]=>
   object(GMP)#%d (1) {
     ["num"]=>
-    string(2) "36"
+    string(3) "-36"
   }
 }
 array(2) {