-
Notifications
You must be signed in to change notification settings - Fork 7.9k
RFC: Add the RoundingMode enum #14833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
04420a7
7b54dc6
bb2ecfa
9e073ab
600d854
416d8be
dc23ed9
86d7647
129d3f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -696,15 +696,20 @@ PHP_FUNCTION(bcround) | |
zend_string *numstr; | ||
zend_long precision = 0; | ||
zend_long mode = PHP_ROUND_HALF_UP; | ||
zend_object *mode_object = NULL; | ||
bc_num num = NULL, result; | ||
|
||
ZEND_PARSE_PARAMETERS_START(1, 3) | ||
Z_PARAM_STR(numstr) | ||
Z_PARAM_OPTIONAL | ||
Z_PARAM_LONG(precision) | ||
Z_PARAM_LONG(mode) | ||
Z_PARAM_OBJ_OF_CLASS(mode_object, rounding_mode_ce) | ||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
if (mode_object != NULL) { | ||
mode = php_math_round_mode_from_enum(mode_object); | ||
} | ||
|
||
switch (mode) { | ||
case PHP_ROUND_HALF_UP: | ||
case PHP_ROUND_HALF_DOWN: | ||
|
@@ -716,7 +721,8 @@ PHP_FUNCTION(bcround) | |
case PHP_ROUND_AWAY_FROM_ZERO: | ||
break; | ||
default: | ||
zend_argument_value_error(3, "must be a valid rounding mode (PHP_ROUND_*)"); | ||
/* This is currently unreachable, but might become reachable when new modes are added. */ | ||
zend_argument_value_error(3, " is a rounding mode that is not supported"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how this can happen now? As the value should always be a correct mode from the enum object, turning this into an assertion seems more logical. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cannot happen now (as the comment indicates), but can happen if additional cases are added to the This error message is thus intended to fail safely rather than crashing or returning bogus values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather have this be an assertion and have a test in BC Math that cycles through all the cases of the enum to be sure we don't miss any new ones introduced. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added an additional test based on |
||
return; | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.