rfc:raising_zero_to_power_of_negative_number

This is an old revision of the document!


PHP RFC: Raising zero to the power of negative number

Introduction

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.

var_dump(0 ** -1); //float(INF)
 
var_dump(pow(0, -1)); //float(INF)
 
var_dump(1 / 0); //DivisionByZeroError: Division by zero

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 notice, and for the major version, this operation will throw DivisionByZeroError.

Backward Incompatible Changes

This change will break all code including raising the zero number to a negative power.

Proposed PHP Version(s)

Deprecation Notice in the next minor PHP version 8.4.

Throwing DivisionByZeroError in the next major PHP version: 9.0.

Proposed Voting Choices

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 2024-x-x.

Implementation

References

rfc/raising_zero_to_power_of_negative_number.1705008270.txt.gz · Last modified: 2024/01/11 21:24 by jorg_sowa