negative powers() do not raise a DivisionByZeroError
Description
Raising to a negative power is similar to a division, so applying those to 0 should raise a DivisionByZeroError
The following code:
<?php
echo 0 ** -1;
echo 0 ** -2;
echo pow(0, -4);
Resulted in this output:
INF
INF
INF
But I expected this output instead:
PHP Fatal error: Uncaught DivisionByZeroError: Division by zero
PHP Version
8.1.2
Operating System
N/A
I think it makes sense to throw a DivisionByZeroError here but I'm not sure if it shouldn't rather be classified as a feature since this has been like this forever and likely would break some code out there.
Also, this might need special casing, at least for doubles, since that just calls pow(3) which may set errno or not (with Visual Studio, it does not).
Keep in mind that INF also makes sense for some cases and was only changed to DivisionByZeroError in PHP 8.0 (https://wiki.php.net/rfc/engine_warnings#division_by_zero). Before that, in PHP 7, it was a warning.
If changed, I believe it should be done by using the RFC process, making it first a warning and only from PHP 9.0 an error.
I create a PoC here. https://github.com/php/php-src/compare/master...iluuu1994:php-src:throw-division-by-zero-on-pow-of-base-0-exponent-lt-eq-0
Mathematically the current behavior is incorrect. I think it makes sense to correct this so I'll propose an RFC. The current implementation throws a hard error but we'll need an implementation that just throws a deprecation. That should be a small change though.
Hey @iluuu1994! Are you planning to pursue this RFC? It would be good this code throwing the deprecation before the next major version. If you don't have a time I can assist you.
@jorgsowa Feel free 😊
There has not been any recent activity in this feature request. It will automatically be closed in 14 days if no further action is taken. Please see https://github.com/probot/stale#is-closing-stale-issues-really-a-good-idea to understand why we auto-close stale feature requests.
@TimWolla Any reason to keep this open, given that there's already an RFC + discussion?
given that there's already an RFC + discussion?
Exactly that: There's an RFC and thus it's not actually stale and it is not “Status: Requires RFC“. Jorg's PR will also close this issue once merged. So basically some housekeeping of the issue list.
@jorgsowa 18 days ago you've said you wanted to open the vote barring any new comments (https://externals.io/message/122142#122670). What's the status? :smiley:
Right. I find feature requests useful for sparking ideas, but not much else. Discussion shouldn't happen here, and once there's an existing RFC there's usually a reason it doesn't progress, or it's already been rejected. In either case, a Github issue isn't too useful.
@TimWolla sorry for the delay. I have holidays now and I forgot to start it before. I started the voting phase today.
@iluuu1994 I think feature request are actually useful in the same way as they were useful in the old bug tracker. It's mainly to see the interest (which means number of votes in the old bug tracker and emojis on github). AFAIK closing feature requests because there is an RFC has never been a practice. The feature requests are closed only when merged or rejected. This has been like this for ages.
IMO the fact that the RFC process doesn't support any kind of feedback (without sending +1 emails) is a deficiency in the ML itself. We are planning on proposing a solution to this soon. Keeping an issue as a means to do that would make sense if it were more discoverable. But it's usually not linked from the RFC or from the ML discussion. More often than not, we just have to keep reminding people that discussion shouldn't happen on GitHub, which is a waste of time IMO.
I take feature requests as something that people think would be useful. I actually sometimes use it as ideas to implement. I think that until those ideas are resolved (either implemented or rejected), the feature request should stay open.
Also this is how it's been working for years in the old bug tracker so I don't think this should be changed without a proper process (it means policy RFC).
But is this a documented policy? We've been handling it this way since moving to GitHub issues over 2 years ago. There's even automation to enforce it (which is why this issue was auto-closed). I'm not sure if it makes sense to use the RFC process for this policy when the vast majority of voters do not deal with GH issues, and when there are some non-voters that do.
Feature requests are certainly useful, at least until they get their dedicated RFC or if they don't require one at all. After that, the issue just becomes something that shouldn't be used anymore (technical details are discussed on the PR, user-facing ones on the ML) and then likely forgotten when the RFC is either rejected or accepted.
There's just automation to close inactive feature request that requires RFC. Personally I really don't like it and think we should remove it as it's closing up good ideas.
Issues are still very useful for people searching for ideas as an info that this being worked on. There are much easier to find than discussions on mailing list. IMHO it should be just linked and kept untill all is resolved.
I suggested policy RFC because it is currently the only form how to resolve disagreements.
This was implemented by https://github.com/php/php-src/pull/13128, closing this manually now.
Heh, I honestly did not not close this on purpose. Case in point.
Heh, I honestly did not not close this on purpose. Case in point.
I'm confused, this feature request is implemented so why did you want to keep it open? EDIT: I missed the double negation. nvm