-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Comments
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) |
The rounding behavior for approximate-value numbers seems to be implementation-defined. Do we have to fix it?
|
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. |
@xuhui-lu you could comment |
/assign @xuhui-lu |
Please edit this comment or add a new comment to complete the following informationNot a bug
Duplicate bug
BugNote: Make Sure that 'component', and 'severity' labels are added 1. Root Cause Analysis (RCA) (optional)2. Symptom (optional)3. All Trigger Conditions (optional)4. Workaround (optional)5. Affected versions6. Fixed versionsv5.0.0-rc |
( AffectedVersions ) fields are empty. |
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
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 |
+-----------------------+
The text was updated successfully, but these errors were encountered: