Skip to content

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

Merged
SakiTakamachi merged 4 commits into
php:masterfrom
SakiTakamachi:bcmath/modified_scale_when_return_zero
Mar 14, 2025
Merged

ext/bcmath: If the result is 0, n_scale is set to 0.#18056
SakiTakamachi merged 4 commits into
php:masterfrom
SakiTakamachi:bcmath/modified_scale_when_return_zero

Conversation

@SakiTakamachi

@SakiTakamachiSakiTakamachi commented Mar 14, 2025

Copy link
Copy Markdown
Member

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.

@SakiTakamachiSakiTakamachi 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
SakiTakamachiforce-pushed the bcmath/modified_scale_when_return_zero branch from bc2ebf9 to de37c55CompareMarch 14, 2025 00:39
@SakiTakamachi
SakiTakamachiforce-pushed the bcmath/modified_scale_when_return_zero branch 2 times, most recently from 5dd5131 to 0aba848CompareMarch 14, 2025 01:13
@SakiTakamachi
SakiTakamachiforce-pushed the bcmath/modified_scale_when_return_zero branch from 0aba848 to 2fdd2d4CompareMarch 14, 2025 01:23
@SakiTakamachi
SakiTakamachi marked this pull request as ready for review March 14, 2025 02:04
#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
Copy Markdown
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:masterMar 14, 2025
@SakiTakamachi
SakiTakamachi deleted the bcmath/modified_scale_when_return_zero branch March 14, 2025 08:52
Sign up for freeto 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

@SakiTakamachi@ndossche