-
Notifications
You must be signed in to change notification settings - Fork 7.8k
round: Bypass the precision logic when rounding to 0 places #12284
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
base: master
Are you sure you want to change the base?
Conversation
Since phpGH-12220 the implementation of `php_round_helper()`, which performs rounding to an integral value, is easy to verify for correctness up to the floating point precision. If rounding to 0 places is desired, i.e. the userland `round()` function is called with `$precision = 0`, we bypass all logic for the decimal point adjustment and instead directly call `php_round_helper()`. This change fixes the remaining two cases of phpGH-12143 and likely guarantees correct rounding for all possible inputs and `$precision = 0`.
I haven't tried it yet, so this is just a prediction, but I think the results will be incorrect in the following cases.
|
These cases are not handled by this PR. It only handles the case where the second parameter is |
Ah, I understand. I cannot agree to this change. Rounding to the 16th digit is not included as it is a functional modification, but all other cases can be fixed with my changes. And bypassing processing when precision is 0 as a way to make the 16th digit possible is completely wrong. |
This looks sensible? But I must say the precision adjustment code is quite confusing (probably due to the extremely generic variable names...). But overhaul, shouldn't possible issues only be present when using strictly positive precisions? And it seems like it tries to handle those before delegating to the round helper. (Point being I don't totally understand why negative precisions, which will round to an integer value, seems to use the same logic as something rounding to a float val). |
Hi @TimWolla, will you continue this PR? |
Since GH-12220 the implementation of
php_round_helper()
, which performs rounding to an integral value, is easy to verify for correctness up to the floating point precision.If rounding to 0 places is desired, i.e. the userland
round()
function is called with$precision = 0
, we bypass all logic for the decimal point adjustment and instead directly callphp_round_helper()
.This change fixes the remaining two cases of GH-12143 and likely guarantees correct rounding for all possible inputs and
$precision = 0
./cc @SakiTakamachi