mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
ext/gmp: Refactor gmp_fact() to use new ZPP specifier
Not sure it is the best approach to do this one however
This commit is contained in:
parent
5199904c57
commit
2681da4531
1 changed files with 9 additions and 19 deletions
|
@ -1262,33 +1262,23 @@ GMP_BINARY_OP_FUNCTION_EX(gmp_or, mpz_ior);
|
||||||
/* {{{ Calculates factorial function */
|
/* {{{ Calculates factorial function */
|
||||||
ZEND_FUNCTION(gmp_fact)
|
ZEND_FUNCTION(gmp_fact)
|
||||||
{
|
{
|
||||||
zval *a_arg;
|
mpz_ptr gmpnum;
|
||||||
mpz_ptr gmpnum_result;
|
mpz_ptr gmpnum_result;
|
||||||
|
|
||||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||||
Z_PARAM_ZVAL(a_arg)
|
GMP_Z_PARAM_INTO_MPZ_PTR(gmpnum)
|
||||||
ZEND_PARSE_PARAMETERS_END();
|
ZEND_PARSE_PARAMETERS_END();
|
||||||
|
|
||||||
if (Z_TYPE_P(a_arg) == IS_LONG) {
|
if (mpz_sgn(gmpnum) < 0) {
|
||||||
if (Z_LVAL_P(a_arg) < 0) {
|
zend_argument_value_error(1, "must be greater than or equal to 0");
|
||||||
zend_argument_value_error(1, "must be greater than or equal to 0");
|
RETURN_THROWS();
|
||||||
RETURN_THROWS();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mpz_ptr gmpnum;
|
|
||||||
gmp_temp_t temp_a;
|
|
||||||
|
|
||||||
FETCH_GMP_ZVAL(gmpnum, a_arg, temp_a, 1);
|
|
||||||
FREE_GMP_TEMP(temp_a);
|
|
||||||
|
|
||||||
if (mpz_sgn(gmpnum) < 0) {
|
|
||||||
zend_argument_value_error(1, "must be greater than or equal to 0");
|
|
||||||
RETURN_THROWS();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Check that we don't an int that is larger than an unsigned long?
|
||||||
|
// Could use mpz_fits_slong_p() if we revert to using mpz_get_si()
|
||||||
|
|
||||||
INIT_GMP_RETVAL(gmpnum_result);
|
INIT_GMP_RETVAL(gmpnum_result);
|
||||||
mpz_fac_ui(gmpnum_result, zval_get_long(a_arg));
|
mpz_fac_ui(gmpnum_result, mpz_get_ui(gmpnum));
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue