Re: Breaking change of rounding behavior in PHP 8.4
> Le 12 juil. 2024 à 13:24, Christoph M. Becker <[email protected]> a écrit :
>
> Hi all,
>
> there has been a "small" change in the rounding logic of
> _php_math_round()[1] a couple of months ago. A respective ticket,
> claiming the new behavior would be a bug[2] had been filed a while ago
> without proper triage so far. I'm bringing this to your attention,
> because I'm afraid that there will be (many) more bug reports about this
> in the future (note that the change only affects master, and only PHP
> 8.4.0alpha1 has been released yet, so it is probably not widespreadly
> tested yet). At the very least we should be sure that we want to keep
> this change, and document it well, to avoid discussions in every filed
> ticket.
>
> My personal stance on this is simple: floating point arithmetic is not
> exact per se, and changes to how PHP handles the details should only be
> introduced, if they clearly improve things. This change apparently
> improves some cases, but worsens others. Thus, I think the change
> should better be reverted, and if at all, postponed to PHP 9, since I
> neither regard this change as bug fix nor as a feature.
>
> What do you think?
>
> [1] <https://github.com/php/php-src/pull/12222>
> [2] <https://github.com/php/php-src/issues/14332>
>
> Cheers,
> Christoph
Hi,
See [1] and [2], which motivated the change.
I expect that round($anything) == (int) round($anything)
for any float between
PHP_INT_MIN and PHP_INT_MAX, and I think that the change fixed that .
Therefore, I am for keeping the change, and ensuring that there are test cases for
4503599627370495.5 (the largest float with fractional part).
—Claude
[1]: https://github.com/php/php-src/issues/12143#issuecomment-1713465981
[2]: https://3v4l.org/3Q7BC
Thread (10 messages)