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

types: floatStrToIntStr will failed in some case such as the param is +999.9999e2 #11376

Merged
merged 8 commits into from Jul 26, 2019

Conversation

H-ZeX
Copy link
Contributor

@H-ZeX H-ZeX commented Jul 23, 2019

What problem does this PR solve?

In the origin floatStrToIntStr, it may fail in some case

  1. It will round the float str while numNextDot is +/- in some case
  2. It will fail in +999.9999e2(return ,00000) because the roundIntStr can not handler +/- correctly.

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch

Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
@codecov
Copy link

codecov bot commented Jul 23, 2019

Codecov Report

Merging #11376 into master will increase coverage by 0.7291%.
The diff coverage is n/a.

@@               Coverage Diff                @@
##             master     #11376        +/-   ##
================================================
+ Coverage   81.3776%   82.1068%   +0.7291%     
================================================
  Files           424        425         +1     
  Lines         90939      94360      +3421     
================================================
+ Hits          74004      77476      +3472     
+ Misses        11620      11488       -132     
- Partials       5315       5396        +81

@XuHuaiyu
Copy link
Contributor

/run-all-tests

@H-ZeX
Copy link
Contributor Author

H-ZeX commented Jul 24, 2019

/run-all-tests

@zz-jason
Copy link
Member

@H-ZeX please follow https://github.com/pingcap/tidb/blob/master/CONTRIBUTING.md to refine the PR title.

@H-ZeX H-ZeX changed the title Fix bug of floatStrToIntStr types: floatStrToIntStr will failed in some case such as +999.9999e2 Jul 24, 2019
@H-ZeX H-ZeX changed the title types: floatStrToIntStr will failed in some case such as +999.9999e2 types: floatStrToIntStr will failed in some case such as the param is +999.9999e2 Jul 24, 2019
@H-ZeX H-ZeX changed the title types: floatStrToIntStr will failed in some case such as the param is +999.9999e2 types: floatStrToIntStr will failed in some case such as the param is +999.9999e2 Jul 24, 2019
types/convert.go Outdated
func roundIntStr(numNextDot byte, intStr string) string {
if numNextDot < '5' {
return intStr
}
retStr := []byte(intStr)
for i := len(intStr) - 1; i >= 0; i-- {
if !isDigit(intStr[i]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here i must be 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but this a valid int string, so we needn't to check whether it is 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i must be 0, can we move if !isDigit(intStr[i]) logic to outside the for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Signed-off-by: H-ZeX <hzx20112012@gmail.com>
@H-ZeX
Copy link
Contributor Author

H-ZeX commented Jul 26, 2019

ping @crazycs520

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crazycs520 crazycs520 added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 26, 2019
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zz-jason zz-jason added status/can-merge Indicates a PR has been approved by a committer. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 26, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Jul 26, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Jul 26, 2019

@H-ZeX merge failed.

@zz-jason zz-jason merged commit 5611acd into pingcap:master Jul 26, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Jul 26, 2019

cherry pick to release-2.1 failed

@sre-bot
Copy link
Contributor

sre-bot commented Jul 26, 2019

cherry pick to release-3.0 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression status/can-merge Indicates a PR has been approved by a committer. type/bug-fix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants