问题描述
- php,谁能帮我解释下这个代码
-
PHP_FUNCTION(bcdiv)
{
char *left, *right;
size_t left_len, right_len;
zend_long scale_param = 0;
bc_num first, second, result;
int scale = (int)BCG(bc_precision), argc = ZEND_NUM_ARGS();if (zend_parse_parameters(argc, "ss|l", &left, &left_len, &right, &right_len, &scale_param) == FAILURE) { return; } if (argc == 3) { scale = (int) ((int)scale_param < 0 ? 0 : scale_param); } bc_init_num(&first); bc_init_num(&second); bc_init_num(&result); php_str2num(&first, left); php_str2num(&second, right); switch (bc_divide(first, second, &result, scale)) { case 0: /* OK */ if (result->n_scale > scale) { result = split_bc_num(result); result->n_scale = scale; } RETVAL_STR(bc_num2str(result)); break; case -1: /* division by zero */ php_error_docref(NULL, E_WARNING, "Division by zero"); break; } bc_free_num(&first); bc_free_num(&second); bc_free_num(&result); return;
}
/* }}} *//* {{{ proto string bcmod(string left_operand, string right_operand)
Returns the modulus of the two arbitrary precision operands */
PHP_FUNCTION(bcmod)
{
char *left, *right;
size_t left_len, right_len;
bc_num first, second, result;if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &left, &left_len, &right, &right_len) == FAILURE) { return; } bc_init_num(&first); bc_init_num(&second); bc_init_num(&result); bc_str2num(&first, left, 0); bc_str2num(&second, right, 0); switch (bc_modulo(first, second, &result, 0)) { case 0: RETVAL_STR(bc_num2str(result)); break; case -1: php_error_docref(NULL, E_WARNING, "Division by zero"); break; } bc_free_num(&first); bc_free_num(&second); bc_free_num(&result); return;
}
解决方案
这是C++代码,不是php的。应该是用c++写php扩展模块。
解决方案二:
谁能解释下这段代码
时间: 2024-09-15 05:22:05