-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Fixed GH-16236: Fixed a bug in BcMath\Number::pow()
and bcpow()
when raising negative powers of 0
.
#16694
Conversation
8a04775
to
fb80440
Compare
fb80440
to
c048993
Compare
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 do wonder if we shouldn't have this throw even in 8.4 for bcpow, as this feels like a bugfix to me.
ext/bcmath/libbcmath/src/bcmath.h
Outdated
@@ -173,7 +173,7 @@ typedef enum { | |||
|
|||
raise_mod_status bc_raisemod(bc_num base, bc_num exponent, bc_num mod, bc_num *result, size_t scale); | |||
|
|||
void bc_raise(bc_num base, long exponent, bc_num *resul, size_t scale); | |||
bool bc_raise(bc_num num1, long exponent, bc_num *result, size_t scale); |
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 prefer to continue using base
ext/bcmath/tests/gh16236.phpt
Outdated
/** | ||
* The existing bcpow() specification returns 0 for negative powers. | ||
* This is mathematically incorrect and will need to be changed to raise an error at some point. | ||
* This test is to ensure the existing specifications until the specifications are changed. | ||
*/ | ||
bcpow('0', '-2'); |
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.
Please add a stub of this to https://wiki.php.net/rfc/deprecations_php_8_5 so it is not forgotten, or follow-up PR to make this emit an E_WARNING or Throwing on master.
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.
Var_dup the result of this to see what the output is?
Indeed, hard to see any value in getting 0 here... OK, I'll fix it |
Done & fixed var name |
d77a4dc
to
4cfc788
Compare
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.
Fix itself looks fine, but please see comment about the test
ext/bcmath/tests/bcpow.phpt
Outdated
@@ -6,7 +6,35 @@ bcmath | |||
bcmath.scale=0 | |||
--FILE-- | |||
<?php | |||
require(__DIR__ . "/run_bcmath_tests_function.inc"); | |||
// slightly modified run_bcmath_tests_function.inc for bcpow testing |
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 think it's better to not copy&paste the code. Instead, modify run_bcmath_tests_function.inc
to catch exceptions,and if there is one, just print the exception message instead of the result. This will reduce code duplication and would still test these cases. It also generalises nicer.
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, fixed it in 2e44b1f
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!
Shouldn't this be deprecated first? It's basically the same case as with |
hm... |
I thought about this for a bit. For But Therefore, I would consider this a "bug fix" rather than a "feature change" and expect it to be fixed in 8.4. |
Returning In any case, considering we already have an RFC with unanimous in support for basically this case, I don't see the value of running this again past internals. Ideally, this should have been caught by the RFC in question but note that GMP already throws a Aside: it feels like the RFC for standard should have been an |
I agree that's a bug, but removing it without any deprecation will cause an impact on the user's code. There were cases in the past where such fixes were causing problems: Fixing such issues without deprecations puts PHP in an unreliable position. |
Fixing bugs is not an unreliable position. If an upgrade finds a bug by shouting early, then it is a positive. This mentality that incorrect code needs to continue working really needs to go away. |
In a little while days I plan to merge this. |
BcMath\Number::pow()
when raising negative powers of 0
.BcMath\Number::pow()
and bcpow()
when raising negative powers of 0
.
* PHP-8.4: Fixed a bug in BcMath\Number::pow() and bcpow() when raising negative powers of 0. (#16694)
* PHP-8.4: [skip ci] NEWS for #16694
Fixes #16236
The existing functionbcpow()
returns0
when it is a negative power of0
. Changing this specification is a BC Break, so will not do so in this PR.bcpow()
should be modified in a similar way.The
BcMath\Number
class is a class added in 8.4, so an error will be generated.