BigInteger: improve detection of newly introduced GMP bug

This commit is contained in:
terrafrost 2024-11-29 00:35:25 -06:00
parent 05085f4df0
commit 8de7a893c2

View File

@ -245,9 +245,17 @@ class Math_BigInteger
function __construct($x = 0, $base = 10) function __construct($x = 0, $base = 10)
{ {
if (!defined('MATH_BIGINTEGER_MODE')) { if (!defined('MATH_BIGINTEGER_MODE')) {
// https://github.com/php/php-src/commit/e0a0e216a909dc4ee4ea7c113a5f41d49525f02e broke GMP
// https://github.com/php/php-src/commit/424ba0f2ff9677d16b4e339e90885bd4bc49fcf1 fixed it
// see https://github.com/php/php-src/issues/16870 for more info
if (version_compare(PHP_VERSION, '8.2.26', '<')) {
$gmpOK = true;
} else {
$gmpOK = !in_array(PHP_VERSION_ID, array(80226, 80314, 80400, 80401));
}
switch (true) { switch (true) {
// PHP 8.4.0 and 8.4.1 don't work with GMP per https://github.com/php/php-src/issues/16870 case extension_loaded('gmp') && $gmpOK:
case extension_loaded('gmp') && !(version_compare(PHP_VERSION, '8.4.0', '>=') && version_compare(PHP_VERSION, '8.4.1', '<=')):
define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP); define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP);
break; break;
case extension_loaded('bcmath'): case extension_loaded('bcmath'):