mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Merge branch 'PHP-8.4'
This commit is contained in:
commit
79c71c9f0b
2 changed files with 47 additions and 2 deletions
|
@ -1288,12 +1288,37 @@ ZEND_FUNCTION(gmp_pow)
|
||||||
|
|
||||||
if (Z_TYPE_P(base_arg) == IS_LONG && Z_LVAL_P(base_arg) >= 0) {
|
if (Z_TYPE_P(base_arg) == IS_LONG && Z_LVAL_P(base_arg) >= 0) {
|
||||||
INIT_GMP_RETVAL(gmpnum_result);
|
INIT_GMP_RETVAL(gmpnum_result);
|
||||||
|
if (exp >= INT_MAX) {
|
||||||
|
mpz_t base_num, exp_num, mod;
|
||||||
|
mpz_init(base_num);
|
||||||
|
mpz_init(exp_num);
|
||||||
|
mpz_init(mod);
|
||||||
|
mpz_set_si(base_num, Z_LVAL_P(base_arg));
|
||||||
|
mpz_set_si(exp_num, exp);
|
||||||
|
mpz_set_ui(mod, UINT_MAX);
|
||||||
|
mpz_powm(gmpnum_result, base_num, exp_num, mod);
|
||||||
|
mpz_clear(mod);
|
||||||
|
mpz_clear(exp_num);
|
||||||
|
mpz_clear(base_num);
|
||||||
|
} else {
|
||||||
mpz_ui_pow_ui(gmpnum_result, Z_LVAL_P(base_arg), exp);
|
mpz_ui_pow_ui(gmpnum_result, Z_LVAL_P(base_arg), exp);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mpz_ptr gmpnum_base;
|
mpz_ptr gmpnum_base;
|
||||||
FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base, 1);
|
FETCH_GMP_ZVAL(gmpnum_base, base_arg, temp_base, 1);
|
||||||
INIT_GMP_RETVAL(gmpnum_result);
|
INIT_GMP_RETVAL(gmpnum_result);
|
||||||
|
if (exp >= INT_MAX) {
|
||||||
|
mpz_t exp_num, mod;
|
||||||
|
mpz_init(exp_num);
|
||||||
|
mpz_init(mod);
|
||||||
|
mpz_set_si(exp_num, exp);
|
||||||
|
mpz_set_ui(mod, UINT_MAX);
|
||||||
|
mpz_powm(gmpnum_result, gmpnum_base, exp_num, mod);
|
||||||
|
mpz_clear(mod);
|
||||||
|
mpz_clear(exp_num);
|
||||||
|
} else {
|
||||||
mpz_pow_ui(gmpnum_result, gmpnum_base, exp);
|
mpz_pow_ui(gmpnum_result, gmpnum_base, exp);
|
||||||
|
}
|
||||||
FREE_GMP_TEMP(temp_base);
|
FREE_GMP_TEMP(temp_base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
20
ext/gmp/tests/gmp_pow_fpe.phpt
Normal file
20
ext/gmp/tests/gmp_pow_fpe.phpt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
--TEST--
|
||||||
|
gmp_pow() floating point exception
|
||||||
|
--EXTENSIONS--
|
||||||
|
gmp
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$g = gmp_init(256);
|
||||||
|
|
||||||
|
var_dump(gmp_pow($g, PHP_INT_MAX));
|
||||||
|
var_dump(gmp_pow(256, PHP_INT_MAX));
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
object(GMP)#2 (1) {
|
||||||
|
["num"]=>
|
||||||
|
string(%d) "%s"
|
||||||
|
}
|
||||||
|
object(GMP)#2 (1) {
|
||||||
|
["num"]=>
|
||||||
|
string(%d) "%s"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue