xy720 opened a new pull request, #64622:
URL: https://github.com/apache/doris/pull/64622
### What problem does this PR solve?
Problem Summary:
`SELECT round(23900/293, 2)` returns `81.56999999999999` instead of `81.57`.
The same problems exist in all round-like functions (round / round_bankers /
ceil / floor / truncate).
Root cause:
Round(double, n) on a double cannot land on a clean N-decimal value: 81.57
is not representable in binary, the nearest double bit pattern is
81.56999999999999488....
And the formatter "%.16g," for double it will keep 16 significant digits
(see doris 4.x docs for DOUBLE type), which faithfully prints those tail
digits.
Round-like function themselves are computing correctly, the return value
just cannot fit cleanly into a double container.
Behavior change:
Round-like functions with arguments (double, const_int >= 0) now retrun
column type DECIMAL instead of DOUBLE, matching MySQL. DOUBLE values with |x|
>= 1e15 no longer fit through the inserted cast and become NULL (or
ARITHMETIC_OVERFLOW_ERROR in strict mode); such double values already render as
scientific notation under the prior behavior, so the cost is small.
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [x] Regression test
- [x] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [x] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [x] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR should
merge into -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]