Added support for libbcmath's bc_raisemod function as bc_powmod()

This commit is contained in:
Sara Golemon 2002-12-10 19:04:27 +00:00
parent 91a6272972
commit 51c9f2c64b
2 changed files with 34 additions and 0 deletions

View File

@ -42,6 +42,7 @@ function_entry bcmath_functions[] = {
PHP_FE(bcsqrt, NULL)
PHP_FE(bcscale, NULL)
PHP_FE(bccomp, NULL)
PHP_FE(bc_powmod, NULL)
{NULL, NULL, NULL}
};
@ -329,6 +330,38 @@ PHP_FUNCTION(bcmod)
}
/* }}} */
/* {{{ proto string bc_powmod(string x, string y, string mod [, int scale])
Returns the value of an arbitrary precision number raised to the power of another reduced by a modulous */
PHP_FUNCTION(bc_powmod)
{
char *left, *right, *modulous;
int left_len, right_len, modulous_len;
bc_num first, second, mod, result;
int scale=bc_precision;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_C, "sss|l", &left, &left_len, &right, &right_len, &modulous, &modulous_len, &scale) == FAILURE) {
WRONG_PARAM_COUNT;
}
bc_init_num(&first TSRMLS_CC);
bc_init_num(&second TSRMLS_CC);
bc_init_num(&mod TSRMLS_CC);
bc_init_num(&result TSRMLS_CC);
bc_str2num(&first, left, scale TSRMLS_CC);
bc_str2num(&second, right, scale TSRMLS_CC);
bc_str2num(&mod, modulous, scale TSRMLS_CC);
bc_raisemod(first, second, mod, &result, scale TSRMLS_CC);
Z_STRVAL_P(return_value) = bc_num2str(result);
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
Z_TYPE_P(return_value) = IS_STRING;
bc_free_num(&first);
bc_free_num(&second);
bc_free_num(&mod);
bc_free_num(&result);
return;
}
/* }}} */
/* {{{ proto string bcpow(string x, string y [, int scale])
Returns the value of an arbitrary precision number raised to the power of another */
PHP_FUNCTION(bcpow)

View File

@ -60,6 +60,7 @@ PHP_FUNCTION(bcpow);
PHP_FUNCTION(bcsqrt);
PHP_FUNCTION(bccomp);
PHP_FUNCTION(bcscale);
PHP_FUNCTION(bc_powmod);
#else