diff options
-rw-r--r-- | ext/bcmath/bcmath.c | 11 | ||||
-rw-r--r-- | ext/bcmath/tests/bcscale_variation003.phpt | 18 |
2 files changed, 26 insertions, 3 deletions
diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c index e8b87dceff..6020a7c6d7 100644 --- a/ext/bcmath/bcmath.c +++ b/ext/bcmath/bcmath.c @@ -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(); + old_scale = BCG(bc_precision); + + if (ZEND_NUM_ARGS() == 1) { BCG(bc_precision) = ((int)new_scale < 0) ? 0 : new_scale; + } - RETURN_TRUE; + RETURN_LONG(old_scale); } /* }}} */ diff --git a/ext/bcmath/tests/bcscale_variation003.phpt b/ext/bcmath/tests/bcscale_variation003.phpt new file mode 100644 index 0000000000..b1c541644c --- /dev/null +++ b/ext/bcmath/tests/bcscale_variation003.phpt @@ -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) |