Skip to content

ext/bcmath: If the result is 0, n_scale is set to 0. #18056

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

Merged

Conversation

SakiTakamachi
Copy link
Member

@SakiTakamachi SakiTakamachi commented Mar 14, 2025

If the result is 0, there is no point in having a scale.

In the case of functions, when converting to string, the decimal part is automatically filled with 0 to match the set scale, so bc_num itself does not need to hold an extra scale.

Even with the Number class, objects retain the scale, so bc_num itself does not need to retain it.

If bc_num holds an unnecessary scale, subsequent calculations using the Number class will result in unnecessary calculations.

notes

The only exception is round(), which is designed so that the n_scale of bc_num affects the return value.
So I changed it so that it doesn't affect the return value.

@SakiTakamachi SakiTakamachi changed the title ext/bcmath: If the result is 0, n_scale is set to 0. ext/bcmath: If the result is 0, n_scale is set to 0. Mar 14, 2025
@SakiTakamachi SakiTakamachi force-pushed the bcmath/modified_scale_when_return_zero branch from bc2ebf9 to de37c55 Compare March 14, 2025 00:39
@SakiTakamachi SakiTakamachi force-pushed the bcmath/modified_scale_when_return_zero branch 2 times, most recently from 5dd5131 to 0aba848 Compare March 14, 2025 01:13
@SakiTakamachi SakiTakamachi force-pushed the bcmath/modified_scale_when_return_zero branch from 0aba848 to 2fdd2d4 Compare March 14, 2025 01:23
@SakiTakamachi SakiTakamachi marked this pull request as ready for review March 14, 2025 02:04
@@ -18,7 +18,7 @@
#include "private.h"
#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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment describing the meaning of the return value

@SakiTakamachi SakiTakamachi merged commit 32547f1 into php:master Mar 14, 2025
1 check passed
@SakiTakamachi SakiTakamachi deleted the bcmath/modified_scale_when_return_zero branch March 14, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants