Skip to content

RFC: Raising zero to the power of negative number #13128

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

Conversation

jorgsowa
Copy link
Contributor

@jorgsowa jorgsowa force-pushed the power-division-by-zero-deprecation branch from 754daee to fb149f6 Compare January 11, 2024 21:32
@TimWolla TimWolla added the RFC label Jan 12, 2024
@jorgsowa jorgsowa force-pushed the power-division-by-zero-deprecation branch from fb149f6 to ea8a19f Compare February 8, 2024 22:10
@jorgsowa jorgsowa force-pushed the power-division-by-zero-deprecation branch from ea8a19f to c8c4d4b Compare February 22, 2024 21:51
static zend_result safe_pow(double *result, double base, double exponent)
{
if (base == 0.0 && exponent < 0.0) {
zend_power_base_0_exponent_lt_eq_0_error();
Copy link
Member

@iluuu1994 iluuu1994 Apr 5, 2024

Choose a reason for hiding this comment

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

This should likely check for EG(exception) and return FAILURE in that case (for throwing error handlers). Usages of safe_pow should propagate this return value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what I should change here. The changes should not throw an exception but the deprecation note. In PHP 9.0 it should throw an exception, but this PR is aimed at 8.4. The same note applies to your second comment.

Copy link
Member

Choose a reason for hiding this comment

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

Warnings can be promoted from error handlers to exceptions. In these cases, often, the program flow must be adjusted in some way. Anyway, I looked at the way pow_function_base()s return value is used, and apparently it indicates not whether the operation was successful, but whether the two operand types support the pow operation. So a change is probably not necessary here.

@jorgsowa jorgsowa marked this pull request as draft April 21, 2024 00:04
@jorgsowa jorgsowa force-pushed the power-division-by-zero-deprecation branch from 661b445 to 620b2fd Compare April 25, 2024 20:06
@iluuu1994
Copy link
Member

@jorgsowa I'm assuming this is ready to have another look?

@iluuu1994 iluuu1994 self-assigned this Apr 30, 2024
@iluuu1994
Copy link
Member

Seems like the comments are still unaddressed. Please ping me once you've made the relevant changes, or if you need help with them.

@jorgsowa
Copy link
Contributor Author

jorgsowa commented May 6, 2024

Thanks for review @iluuu1994. I changed the status to Draft to not take the time of the reviewers when the PR is not finished. Now I have added the function fpow and addressed all comments. I will still wait for the tests to pass until I change it back to the version to review.

@jorgsowa jorgsowa marked this pull request as ready for review May 7, 2024 16:52
@jorgsowa jorgsowa requested a review from kocsismate as a code owner May 7, 2024 16:52
@jorgsowa jorgsowa requested a review from iluuu1994 May 8, 2024 21:52
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

This looks good to me. Thanks for the changes! You can ignore the nit, I'll adjust it before merging.

Comment on lines +5 to +19
$values = [
234,
-234,
23.45e1,
-23.45e1,
0xea,
0352,
"234",
"234.5",
"23.45e1",
true,
false,
pow(0, -2),
acos(1.01),
];
Copy link
Member

Choose a reason for hiding this comment

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

I believe this is an unrelated change: The array contents appear to be identical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. I reformatted the code as I have already touched the file within PR.

Copy link
Member

Choose a reason for hiding this comment

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

Unrelated changes, such as this reformatting, make it harder to see what changed in the test over time, e.g. within the git blame output: As a reader I would need to think whether the changes are significant or not. As an example, this change makes it harder to determine if this RFC added a new test case to properly cover the changed code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it would be good to reformat all such tests in a separate PR? I also had some cases in the past when I was modifying existing tests and the code was not properly formatted so I just included this in PR. If we reformat everything at once then we don't have such discussions again.

Copy link
Member

Choose a reason for hiding this comment

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

I'm generally against reformatting, but this formatting is just objectively bad. So, doing it in a separate PR makes sense to me.

Comment on lines +5 to +19
$values = [
234,
-234,
23.45e1,
-23.45e1,
0xea,
0352,
"234",
"234.5",
"23.45e1",
true,
false,
pow(0, -2),
acos(1.01),
];
Copy link
Member

Choose a reason for hiding this comment

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

ditto.

@jorgsowa jorgsowa force-pushed the power-division-by-zero-deprecation branch from de1b634 to 2096685 Compare May 13, 2024 22:36
@jorgsowa
Copy link
Contributor Author

I added an entry about deprecation to NEWS.

@TimWolla
Copy link
Member

I added an entry about deprecation to NEWS.

Either both NEWS and UPGRADING should be adjusted, or neither of them. Within NEWS, the [RFC] tag is not used historically and looks odd.

@jorgsowa
Copy link
Contributor Author

@TimWolla thank your comments. I adjusted the entry in NEWS. I was following the existing tag in the file but changed to the more common convention. Also, I added an entry to the UPGRADING file.

@iluuu1994 iluuu1994 closed this in 23afe57 May 22, 2024
@iluuu1994
Copy link
Member

Thanks @jorgsowa! Merged without the formatting changes. I also fixed a small bug in zend_binary_op_produces_error(). Feel free to mark the RFC as implemented. Please also adjust your editor settings to use tabs instead of spaces for C files. These are easy to miss in reviews (I don't use the Refined GitHub extension because it lags).

@jorgsowa
Copy link
Contributor Author

Thank you for your help with this PR. I will prepare PR with the reformatting of those test snippets and will change my code style configuration.

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.

negative powers() do not raise a DivisionByZeroError
3 participants