Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round result is different depending on whether its argument is exact or approximate #1108

Closed
zimulala opened this issue Apr 18, 2016 · 8 comments · Fixed by #21324
Closed
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug. type/enhancement The issue or PR belongs to an enhancement.

Comments

@zimulala
Copy link
Contributor

zimulala commented Apr 18, 2016

Round result is different depending on whether its argument is exact or approximate:
For exact-value numbers, it uses “round half away from zero” rule.
For approximate-value numbers, it uses the “round to nearest even” rule.
See: https://dev.mysql.com/doc/refman/5.7/en/precision-math-rounding.html

1.What did you do?
select cast(25E-1 as signed)

2.What did you expect to see?
+-----------------------+
| cast(25E-1 as signed) |
+-----------------------+
| 2 |
+-----------------------+

3.What did you see instead?
Now they all use “round half away from zero” rule.
+-----------------------+
| cast(25E-1 as signed) |
+-----------------------+
| 3 |
+-----------------------+

@ngaut ngaut added the type/enhancement The issue or PR belongs to an enhancement. label Jun 18, 2016
@ngaut ngaut added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. labels Oct 23, 2018
@ghost
Copy link

ghost commented Jul 23, 2020

Confirming I can still reproduce this against master:

select cast(25E-1 as signed);

..


mysql> select cast(25E-1 as signed);
+-----------------------+
| cast(25E-1 as signed) |
+-----------------------+
|                     3 |
+-----------------------+
1 row in set (0.00 sec)

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-821-gfe07417e6
Edition: Community
Git Commit Hash: fe07417e6b2f28eb334117d44640d0760d7e9866
Git Branch: master
UTC Build Time: 2020-07-22 12:51:37
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

@ghost ghost added the type/bug The issue is confirmed as a bug. label Jul 23, 2020
@dyzsr
Copy link
Contributor

dyzsr commented Oct 19, 2020

The rounding behavior for approximate-value numbers seems to be implementation-defined. Do we have to fix it?

For approximate-value numbers, the result depends on the C library. On many systems, this means that ROUND() uses the “round to nearest even” rule: A value with a fractional part exactly half way between two integers is rounded to the nearest even integer.

@jebter jebter added the sig/execution SIG execution label Nov 9, 2020
@xuhui-lu
Copy link
Contributor

Is this issue still open? If so, I am willing to offer help.

@ichn-hu
Copy link
Contributor

ichn-hu commented Nov 23, 2020

Is this issue still open? If so, I am willing to offer help.

Sure, it is still open, thank you in advance of your fixing PR.

@ichn-hu
Copy link
Contributor

ichn-hu commented Nov 23, 2020

@xuhui-lu you could comment /assign @xuhui-lu to assign yourself on this issue.

@xuhui-lu
Copy link
Contributor

/assign @xuhui-lu

@ti-srebot
Copy link
Contributor

ti-srebot commented Dec 10, 2020

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

v5.0.0-rc

@ti-srebot
Copy link
Contributor

( AffectedVersions ) fields are empty.
The values in ( FixedVersions ) fields are incorrect.

xhebox pushed a commit to xhebox/tidb that referenced this issue Sep 28, 2021
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
xhebox pushed a commit to xhebox/tidb that referenced this issue Oct 8, 2021
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
ti-chi-bot pushed a commit that referenced this issue Oct 9, 2021
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants