ext/bcmath: If the result is 0, n_scale is set to 0. - #18056
Merged
SakiTakamachi merged 4 commits intoMar 14, 2025
Merged
Conversation
n_scale is set to 0.0, n_scale is set to 0.
SakiTakamachi
force-pushed
the
bcmath/modified_scale_when_return_zero
branch
from
March 14, 2025 00:39
bc2ebf9 to
de37c55
Compare
SakiTakamachi
force-pushed
the
bcmath/modified_scale_when_return_zero
branch
2 times, most recently
from
March 14, 2025 01:13
5dd5131 to
0aba848
Compare
…ry zeros, and uses that.
SakiTakamachi
force-pushed
the
bcmath/modified_scale_when_return_zero
branch
from
March 14, 2025 01:23
0aba848 to
2fdd2d4
Compare
SakiTakamachi
marked this pull request as ready for review
March 14, 2025 02:04
ndossche
approved these changes
Mar 14, 2025
| #include <stddef.h> | ||
|
|
||
| void bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result) | ||
| size_t bc_round(bc_num num, zend_long precision, zend_long mode, bc_num *result) |
Member
There was a problem hiding this comment.
Please add a comment describing the meaning of the return value
adrian-enspired
pushed a commit
to adrian-enspired/php-src
that referenced
this pull request
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If the result is
0, there is no point in having ascale.In the case of functions, when converting to
string, the decimal part is automatically filled with0to match the setscale, sobc_numitself does not need to hold an extrascale.Even with the
Numberclass, objects retain thescale, sobc_numitself does not need to retain it.If
bc_numholds an unnecessaryscale, subsequent calculations using theNumberclass will result in unnecessary calculations.notes
The only exception is
round(), which is designed so that then_scaleofbc_numaffects the return value.So I changed it so that it doesn't affect the return value.