-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
bab1053
to
5f3a31b
Compare
NEWS
Outdated
(Saki Takamachi) | ||
. Fixed bug GH-17049 (Correctly compare 0 and -0). (Saki Takamachi) |
There was a problem hiding this comment.
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.
ext/bcmath/libbcmath/src/compare.c
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 && |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
5f3a31b
to
28fe1c9
Compare
Fixed! |
0
and -0
0
and -0
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
977c863
to
9f05c40
Compare
The last force push just resolved the NEWS conflict. I'll merge, thanks for the review! |
* PHP-8.4: Correctly compare 0 and -0 (#17051)
fixes #17049