PHP_FUNCTION(bcadd)
{
zend_string *left, *right;
- zend_long scale_param = 0;
+ zend_long scale_param;
+ zend_bool scale_param_is_null = 1;
bc_num first, second, result;
- int scale = BCG(bc_precision);
+ int scale;
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STR(left)
Z_PARAM_STR(right)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(scale_param)
+ Z_PARAM_LONG_OR_NULL(scale_param, scale_param_is_null)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_NUM_ARGS() == 3) {
- if (scale_param < 0 || scale_param > INT_MAX) {
- zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
- RETURN_THROWS();
- }
+ if (scale_param_is_null) {
+ scale = BCG(bc_precision);
+ } else if (scale_param < 0 || scale_param > INT_MAX) {
+ zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
+ RETURN_THROWS();
+ } else {
scale = (int) scale_param;
}
PHP_FUNCTION(bcsub)
{
zend_string *left, *right;
- zend_long scale_param = 0;
+ zend_long scale_param;
+ zend_bool scale_param_is_null = 1;
bc_num first, second, result;
- int scale = BCG(bc_precision);
+ int scale;
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STR(left)
Z_PARAM_STR(right)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(scale_param)
+ Z_PARAM_LONG_OR_NULL(scale_param, scale_param_is_null)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_NUM_ARGS() == 3) {
- if (scale_param < 0 || scale_param > INT_MAX) {
- zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
- RETURN_THROWS();
- }
+ if (scale_param_is_null) {
+ scale = BCG(bc_precision);
+ } else if (scale_param < 0 || scale_param > INT_MAX) {
+ zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
+ RETURN_THROWS();
+ } else {
scale = (int) scale_param;
}
PHP_FUNCTION(bcmul)
{
zend_string *left, *right;
- zend_long scale_param = 0;
+ zend_long scale_param;
+ zend_bool scale_param_is_null = 1;
bc_num first, second, result;
- int scale = BCG(bc_precision);
+ int scale;
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STR(left)
Z_PARAM_STR(right)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(scale_param)
+ Z_PARAM_LONG_OR_NULL(scale_param, scale_param_is_null)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_NUM_ARGS() == 3) {
- if (scale_param < 0 || scale_param > INT_MAX) {
- zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
- RETURN_THROWS();
- }
+ if (scale_param_is_null) {
+ scale = BCG(bc_precision);
+ } else if (scale_param < 0 || scale_param > INT_MAX) {
+ zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
+ RETURN_THROWS();
+ } else {
scale = (int) scale_param;
}
PHP_FUNCTION(bcdiv)
{
zend_string *left, *right;
- zend_long scale_param = 0;
+ zend_long scale_param;
+ zend_bool scale_param_is_null = 1;
bc_num first, second, result;
int scale = BCG(bc_precision);
Z_PARAM_STR(left)
Z_PARAM_STR(right)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(scale_param)
+ Z_PARAM_LONG_OR_NULL(scale_param, scale_param_is_null)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_NUM_ARGS() == 3) {
- if (scale_param < 0 || scale_param > INT_MAX) {
- zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
- RETURN_THROWS();
- }
+ if (scale_param_is_null) {
+ scale = BCG(bc_precision);
+ } else if (scale_param < 0 || scale_param > INT_MAX) {
+ zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
+ RETURN_THROWS();
+ } else {
scale = (int) scale_param;
}
PHP_FUNCTION(bcmod)
{
zend_string *left, *right;
- zend_long scale_param = 0;
+ zend_long scale_param;
+ zend_bool scale_param_is_null = 1;
bc_num first, second, result;
int scale = BCG(bc_precision);
Z_PARAM_STR(left)
Z_PARAM_STR(right)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(scale_param)
+ Z_PARAM_LONG_OR_NULL(scale_param, scale_param_is_null)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_NUM_ARGS() == 3) {
- if (scale_param < 0 || scale_param > INT_MAX) {
- zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
- RETURN_THROWS();
- }
+ if (scale_param_is_null) {
+ scale = BCG(bc_precision);
+ } else if (scale_param < 0 || scale_param > INT_MAX) {
+ zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
+ RETURN_THROWS();
+ } else {
scale = (int) scale_param;
}
bc_free_num(&first);
bc_free_num(&second);
bc_free_num(&result);
- return;
}
/* }}} */
PHP_FUNCTION(bcpowmod)
{
zend_string *left, *right, *modulus;
- zend_long scale_param = 0;
+ zend_long scale_param;
+ zend_bool scale_param_is_null = 1;
bc_num first, second, mod, result;
int scale = BCG(bc_precision);
Z_PARAM_STR(right)
Z_PARAM_STR(modulus)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(scale_param)
+ Z_PARAM_LONG_OR_NULL(scale_param, scale_param_is_null)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_NUM_ARGS() == 4) {
- if (scale_param < 0 || scale_param > INT_MAX) {
- zend_argument_value_error(4, "must be between 0 and %d", INT_MAX);
- RETURN_THROWS();
- }
+ if (scale_param_is_null) {
+ scale = BCG(bc_precision);
+ } else if (scale_param < 0 || scale_param > INT_MAX) {
+ zend_argument_value_error(4, "must be between 0 and %d", INT_MAX);
+ RETURN_THROWS();
+ } else {
scale = (int) scale_param;
}
bc_free_num(&second);
bc_free_num(&mod);
bc_free_num(&result);
- return;
}
/* }}} */
PHP_FUNCTION(bcpow)
{
zend_string *left, *right;
- zend_long scale_param = 0;
+ zend_long scale_param;
+ zend_bool scale_param_is_null = 1;
bc_num first, second, result;
int scale = BCG(bc_precision);
Z_PARAM_STR(left)
Z_PARAM_STR(right)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(scale_param)
+ Z_PARAM_LONG_OR_NULL(scale_param, scale_param_is_null)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_NUM_ARGS() == 3) {
- if (scale_param < 0 || scale_param > INT_MAX) {
- zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
- RETURN_THROWS();
- }
+ if (scale_param_is_null) {
+ scale = BCG(bc_precision);
+ } else if (scale_param < 0 || scale_param > INT_MAX) {
+ zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
+ RETURN_THROWS();
+ } else {
scale = (int) scale_param;
}
bc_free_num(&first);
bc_free_num(&second);
bc_free_num(&result);
- return;
}
/* }}} */
PHP_FUNCTION(bcsqrt)
{
zend_string *left;
- zend_long scale_param = 0;
+ zend_long scale_param;
+ zend_bool scale_param_is_null = 1;
bc_num result;
int scale = BCG(bc_precision);
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STR(left)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(scale_param)
+ Z_PARAM_LONG_OR_NULL(scale_param, scale_param_is_null)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_NUM_ARGS() == 2) {
- if (scale_param < 0 || scale_param > INT_MAX) {
- zend_argument_value_error(2, "must be between 0 and %d", INT_MAX);
- RETURN_THROWS();
- }
+ if (scale_param_is_null) {
+ scale = BCG(bc_precision);
+ } else if (scale_param < 0 || scale_param > INT_MAX) {
+ zend_argument_value_error(2, "must be between 0 and %d", INT_MAX);
+ RETURN_THROWS();
+ } else {
scale = (int) scale_param;
}
PHP_FUNCTION(bccomp)
{
zend_string *left, *right;
- zend_long scale_param = 0;
+ zend_long scale_param;
+ zend_bool scale_param_is_null = 1;
bc_num first, second;
int scale = BCG(bc_precision);
Z_PARAM_STR(left)
Z_PARAM_STR(right)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(scale_param)
+ Z_PARAM_LONG_OR_NULL(scale_param, scale_param_is_null)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_NUM_ARGS() == 3) {
- if (scale_param < 0 || scale_param > INT_MAX) {
- zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
- RETURN_THROWS();
- }
+ if (scale_param_is_null) {
+ scale = BCG(bc_precision);
+ } else if (scale_param < 0 || scale_param > INT_MAX) {
+ zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
+ RETURN_THROWS();
+ } else {
scale = (int) scale_param;
}
PHP_FUNCTION(bcscale)
{
zend_long old_scale, new_scale;
+ zend_bool new_scale_is_null = 1;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(new_scale)
+ Z_PARAM_LONG_OR_NULL(new_scale, new_scale_is_null)
ZEND_PARSE_PARAMETERS_END();
old_scale = BCG(bc_precision);
- if (ZEND_NUM_ARGS() == 1) {
+ if (!new_scale_is_null) {
if (new_scale < 0 || new_scale > INT_MAX) {
zend_argument_value_error(1, "must be between 0 and %d", INT_MAX);
RETURN_THROWS();
}
+
BCG(bc_precision) = (int) new_scale;
}
/** @generate-function-entries */
-function bcadd(string $left_operand, string $right_operand, int $scale = UNKNOWN): string {}
+function bcadd(string $left_operand, string $right_operand, ?int $scale = null): string {}
-function bcsub(string $left_operand, string $right_operand, int $scale = UNKNOWN): string {}
+function bcsub(string $left_operand, string $right_operand, ?int $scale = null): string {}
-function bcmul(string $left_operand, string $right_operand, int $scale = UNKNOWN): string {}
+function bcmul(string $left_operand, string $right_operand, ?int $scale = null): string {}
-function bcdiv(string $dividend, string $divisor, int $scale = UNKNOWN): string {}
+function bcdiv(string $dividend, string $divisor, ?int $scale = null): string {}
-function bcmod(string $dividend, string $divisor, int $scale = UNKNOWN): string {}
+function bcmod(string $dividend, string $divisor, ?int $scale = null): string {}
-function bcpowmod(string $base, string $exponent, string $modulus, int $scale = UNKNOWN): string|false {}
+function bcpowmod(string $base, string $exponent, string $modulus, ?int $scale = null): string|false {}
-function bcpow(string $base, string $exponent, int $scale = UNKNOWN): string {}
+function bcpow(string $base, string $exponent, ?int $scale = null): string {}
-function bcsqrt(string $operand, int $scale = UNKNOWN): string {}
+function bcsqrt(string $operand, ?int $scale = null): string {}
-function bccomp(string $left_operand, string $right_operand, int $scale = UNKNOWN): int {}
+function bccomp(string $left_operand, string $right_operand, ?int $scale = null): int {}
-function bcscale(int $scale = UNKNOWN): int {}
+function bcscale(?int $scale = null): int {}
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcadd, 0, 2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, left_operand, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, right_operand, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()
#define arginfo_bcsub arginfo_bcadd
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcdiv, 0, 2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, dividend, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, divisor, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()
#define arginfo_bcmod arginfo_bcdiv
ZEND_ARG_TYPE_INFO(0, base, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, exponent, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, modulus, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcpow, 0, 2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, base, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, exponent, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcsqrt, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, operand, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bccomp, 0, 2, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, left_operand, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, right_operand, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcscale, 0, 0, IS_LONG, 0)
- ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scale, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()