rfc:raising_zero_to_power_of_negative_number
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:raising_zero_to_power_of_negative_number [2024/01/12 23:03] – improved messages jorg_sowa | rfc:raising_zero_to_power_of_negative_number [2024/04/21 00:06] (current) – Changed status to accepted jorg_sowa | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2024-01-11 | * Date: 2024-01-11 | ||
* Author: Jorg Sowa < | * Author: Jorg Sowa < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 10: | Line 10: | ||
Raising a number to the power of a negative number is equivalent to taking the reciprocal of the number raised to the positive opposite of the power. | Raising a number to the power of a negative number is equivalent to taking the reciprocal of the number raised to the positive opposite of the power. | ||
- | If we raise the number zero to the power of a negative number we end up with the one divided by zero, which gives an undefined result. Currently in PHP, such operation results in `INF`, while explicit division by zero gives a DivisionByZeroError. | + | If we raise the number zero to the power of a negative number we end up with the one divided by zero, which gives an undefined result. Currently in PHP, such operation results in <php>INF</ |
<code php> | <code php> | ||
var_dump(0 ** -1); // | var_dump(0 ** -1); // | ||
+ | var_dump(0 ** -1.1); // | ||
var_dump(pow(0, | var_dump(pow(0, | ||
+ | var_dump(pow(0, | ||
var_dump(1 / 0); // | var_dump(1 / 0); // | ||
Line 22: | Line 24: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | The RFC proposes to change the behavior of this operation to match the division by zero operation. In the next minor version raising a number to the power of a negative number will throw a Deprecation | + | The RFC proposes to change the behavior of this operation to match the division by zero operation. In the next minor version raising a number to the power of a negative number will throw a Deprecation, |
<code php> | <code php> | ||
//PHP 8.4 | //PHP 8.4 | ||
var_dump(0 ** -1); // | var_dump(0 ** -1); // | ||
+ | var_dump(0 ** -1.1); // | ||
- | var_dump(pow(0, | + | var_dump(pow(0, |
+ | var_dump(pow(0, | ||
var_dump(1 / 0); // | var_dump(1 / 0); // | ||
Line 37: | Line 41: | ||
//PHP 9.0 | //PHP 9.0 | ||
var_dump(0 ** -1); // | var_dump(0 ** -1); // | ||
+ | var_dump(0 ** -1.1); // | ||
var_dump(pow(0, | var_dump(pow(0, | ||
+ | var_dump(pow(0, | ||
var_dump(1 / 0); // | var_dump(1 / 0); // | ||
</ | </ | ||
+ | |||
+ | To provide a way to compute the numbers according to the IEEE 754 rules, the RFC proposes adding the function < | ||
+ | |||
+ | <code php> | ||
+ | //PHP 8.4 | ||
+ | var_dump(fpow(0, | ||
+ | var_dump(fpow(0, | ||
+ | </ | ||
+ | |||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | This change will break all code including raising the zero number to a negative power. | + | This change will break code including raising the zero number to a negative power. Such cases may keep their current behavior by using the new < |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Deprecation Notice in the next minor PHP version 8.4. | Deprecation Notice in the next minor PHP version 8.4. | ||
- | Throwing DivisionByZeroError in the next major PHP version: 9.0. | + | Function < |
+ | |||
+ | Throwing | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Line 54: | Line 71: | ||
As per the voting RFC, a yes/no vote with a 2/3 majority is needed for this proposal to be accepted. | As per the voting RFC, a yes/no vote with a 2/3 majority is needed for this proposal to be accepted. | ||
- | Voting started 2024-x-x and closed | + | Voting started |
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Implementation ===== | ===== Implementation ===== | ||
- | https:// | + | https:// |
The implementation is based on Ilija Tovilo' | The implementation is based on Ilija Tovilo' | ||
Line 64: | Line 86: | ||
===== References ===== | ===== References ===== | ||
Issue GH-8015: https:// | Issue GH-8015: https:// | ||
+ | RFC Division by zero: https:// | ||
rfc/raising_zero_to_power_of_negative_number.1705100594.txt.gz · Last modified: 2024/01/12 23:03 by jorg_sowa