[php-src] PR #12291: FIX GH-12143: Remove pre-rounding
| From: | SakiTakamachi | Date: | Sun, 24 Sep 2023 13:01:22 +0000 |
| Subject: | [php-src] PR #12291: FIX GH-12143: Remove pre-rounding | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-23694@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/12291
Author: SakiTakamachi
This PR fixes https://github.com/php/php-src/issues/12143.
cc:
@TimWolla
@Girgias
### Main points
The discussion is scattered all over the place and difficult to understand, so I will summarize the
main points.
## There were two problems with round
1. Values such as
round(0.49999999999999994, 0), where "adding 0.5 will
carry up due to error'' are incorrectly rounded.
2. "pre-round" incorrectly rounds values like round(1.70000000000145,
13)
1 was already fixed and I was trying to fix 2.
## Learn more about problem 2
"pre-round" performs the following calculations.
```
round(1.70000000000145, 13)
1.70000000000145
17000000000014.5 // digit adjustment
17000000000015 // pre-round
1700000000001.5 // digit adjustment
1700000000002 // round
1.700000000002 // return
```
Wrongly rounded due to "pre-round".
## Why is "pre-round" necessary?
The need for "pre-round" is summarized in the following article, "Analysis of the
problems of the previous round() implementation" and "Pre-rounding to the
value's precision if possible".
https://wiki.php.net/rfc/rounding
Simply put, "pre-round" was needed to solve the kind of problem where the result of
round(0.285, 2) is 0.28.
## But the premise is wrong
This PR change is based on the idea that treating FP as if it were a decimal rational number is
logically incorrect.
See #12268 for more information.
## About my changes
"pre-round" processing has been completely removed. And we removed the test for
"pre-round".