rfc:change_the_edge_case_of_round

This is an old revision of the document!


PHP RFC: Change the edge case of round()

Introduction

round() can specify the operating mode when edge case values ​​such as HALF_UP and HALF_DOWN are passed. For example, 0.285 is internally 0.28499999999999998. Should this be considered an edge case? Or is it not an edge case? Regarding this issue, in 2008, the following RFC adopted the policy that 0.285 is considered an edge case. https://wiki.php.net/rfc/rounding

However, there is an opinion that it is wrong to expect decimal-like behavior because FP is just FP. Since 0.28499999999999995 to 0.28500000000000000 are all the same IEEE754 internal representation, and most of their values ​​are less than 0.285, it is unreasonable to treat them as edge cases.

Proposal

This RFC proposes changes that will cause round() to stop expecting decimal behavior to FP and start expecting FP to behave as FP.

// previous behavior
var_dump(round(0.285, 2)); // float(0.29)

// new behavior
var_dump(round(0.285, 2)); // float(0.28)

Backward Incompatible Changes

Regarding edge case determination for round(), some values ​​will no longer be determined as edge cases.

Proposed PHP Version(s)

next PHP 8.x (Currently the target is 8.4)

RFC Impact

To SAPIs

None.

To Existing Extensions

Only “standard” is affected.

To Opcache

No impact.

New Constants

None.

php.ini Defaults

None.

Open Issues

None.

Unaffected PHP Functionality

There is no effect on anything other than “standard”.

Future Scope

None.

Proposed Voting Choices

We will probably vote for or against adding these functions. This requires 2/3 majority.

Implementation

References

Rejected Features

None.

rfc/change_the_edge_case_of_round.1698791534.txt.gz · Last modified: 2023/10/31 22:32 by saki