Skip to content

ext/bcmath - Fixed GH-17049: Correctly compare 0 and -0 #17051

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

Closed
wants to merge 4 commits into from

Conversation

SakiTakamachi
Copy link
Member

fixes #17049

NEWS Outdated
(Saki Takamachi)
. Fixed bug GH-17049 (Correctly compare 0 and -0). (Saki Takamachi)
Copy link
Member

Choose a reason for hiding this comment

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

8.4.2 is tagged already, I guess this branch is outdated.

@@ -45,6 +45,14 @@ bcmath_compare_result _bc_do_compare(bc_num n1, bc_num n2, size_t scale, bool us

/* First, compare signs. */
if (use_sign && n1->n_sign != n2->n_sign) {
if (n1->n_len == 1 && n2->n_len == 1 &&
Copy link
Member

Choose a reason for hiding this comment

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

I understand the change in bc_str2num.
However, I don't fully understand this change: why is this necessary on 8.4 but not on lower branches?

Copy link
Member Author

@SakiTakamachi SakiTakamachi Dec 5, 2024

Choose a reason for hiding this comment

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

This is for Number objects, so it is not necessary for lower branches.

(scale and n->n_scale differ only in Number objects. This happens when explicitly specify the scale in a Number method.)

Perhaps it would be more efficient to compare the scale first in the order of the if conditions?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this maters a lot for performance.
I missed that the scales are not the same for Number objects of course. Please add a small comment to the check to explain this.

@SakiTakamachi
Copy link
Member Author

Fixed!

@SakiTakamachi SakiTakamachi changed the title ext/bcmath - Correctly compare 0 and -0 ext/bcmath - Fixed GH-17049: Correctly compare 0 and -0 Dec 6, 2024
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

See my comment, otherwise LGTM

Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

thanks

@SakiTakamachi
Copy link
Member Author

The last force push just resolved the NEWS conflict. I'll merge, thanks for the review!

SakiTakamachi added a commit that referenced this pull request Dec 6, 2024
* PHP-8.4:
  Correctly compare 0 and -0 (#17051)
@SakiTakamachi SakiTakamachi deleted the fix/gh17049 branch December 6, 2024 16:53
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