Merge branch 'pull-request/778' into bcscale-return-old-value

This commit is contained in:
Christoph M. Becker 2017-09-06 14:28:51 +02:00
commit cf61ec64a4
2 changed files with 27 additions and 4 deletions

View File

@ -581,15 +581,20 @@ PHP_FUNCTION(bccomp)
Sets default scale parameter for all bc math functions */
PHP_FUNCTION(bcscale)
{
zend_long new_scale;
zend_long old_scale, new_scale;
ZEND_PARSE_PARAMETERS_START(1, 1)
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(new_scale)
ZEND_PARSE_PARAMETERS_END();
BCG(bc_precision) = ((int)new_scale < 0) ? 0 : new_scale;
old_scale = BCG(bc_precision);
RETURN_TRUE;
if (ZEND_NUM_ARGS() == 1) {
BCG(bc_precision) = ((int)new_scale < 0) ? 0 : new_scale;
}
RETURN_LONG(old_scale);
}
/* }}} */

View File

@ -0,0 +1,18 @@
--TEST--
bcscale() return value
--SKIPIF--
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
--INI--
bcmath.scale=0
--FILE--
<?php
var_dump(bcscale(1));
var_dump(bcscale(4));
var_dump(bcscale());
var_dump(bcscale());
?>
--EXPECT--
int(0)
int(1)
int(4)
int(4)