diff options
author | Sara Golemon <pollita@php.net> | 2017-11-06 17:27:22 -0500 |
---|---|---|
committer | Sara Golemon <pollita@php.net> | 2017-11-06 17:27:22 -0500 |
commit | 24fd49fbabc7c5ad941095f33d05fe2e41ff667d (patch) | |
tree | 1a5a5787b29af5c203ef1511cd2723e38bb9e65a /ext/bcmath/bcmath.c | |
parent | 6c8b441f876464ca4b1143d9c281e65a3db402ba (diff) | |
parent | b152633ecb2030e2de1f83d2d42193185ea1bc21 (diff) | |
download | php-git-24fd49fbabc7c5ad941095f33d05fe2e41ff667d.tar.gz |
Merge branch 'PHP-7.2'
* PHP-7.2:
Scale support for bcmod()
Diffstat (limited to 'ext/bcmath/bcmath.c')
-rw-r--r-- | ext/bcmath/bcmath.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c index 1186241620..250c751d7a 100644 --- a/ext/bcmath/bcmath.c +++ b/ext/bcmath/bcmath.c @@ -60,9 +60,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_bcdiv, 0, 0, 2) ZEND_ARG_INFO(0, scale) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_bcmod, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_bcmod, 0, 0, 2) ZEND_ARG_INFO(0, left_operand) ZEND_ARG_INFO(0, right_operand) + ZEND_ARG_INFO(0, scale) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_bcpowmod, 0, 0, 3) @@ -354,26 +355,38 @@ PHP_FUNCTION(bcdiv) } /* }}} */ -/* {{{ proto string bcmod(string left_operand, string right_operand) +/* {{{ proto string bcmod(string left_operand, string right_operand [, int scale]) Returns the modulus of the two arbitrary precision operands */ PHP_FUNCTION(bcmod) { zend_string *left, *right; + zend_long scale_param = 0; bc_num first, second, result; + int scale = (int)BCG(bc_precision); - ZEND_PARSE_PARAMETERS_START(2, 2) + ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(left) Z_PARAM_STR(right) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(scale_param) ZEND_PARSE_PARAMETERS_END(); + if (ZEND_NUM_ARGS() == 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, ZSTR_VAL(left)); php_str2num(&second, ZSTR_VAL(right)); - switch (bc_modulo(first, second, &result, 0)) { + switch (bc_modulo(first, second, &result, scale)) { case 0: + if (result->n_scale > scale) { + result = split_bc_num(result); + result->n_scale = scale; + } RETVAL_STR(bc_num2str(result)); break; case -1: |