Skip to content

Commit

Permalink
mysql: fix a corner case bug for MyDecimal (pingcap#1642)
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood authored Aug 26, 2016
1 parent e806ac5 commit e7e2a76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mysql/mydecimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ func doAdd(from1, from2, to *MyDecimal) error {
var x int32
if wordsInt1 > wordsInt2 {
x = from1.wordBuf[0]
} else if wordsInt2 < wordsInt1 {
} else if wordsInt2 > wordsInt1 {
x = from2.wordBuf[0]
} else {
x = from1.wordBuf[0] + from2.wordBuf[0]
Expand Down
4 changes: 3 additions & 1 deletion mysql/mydecimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
package mysql

import (
. "github.com/pingcap/check"
"strings"

. "github.com/pingcap/check"
)

var _ = Suite(&testMyDecimalSuite{})
Expand Down Expand Up @@ -474,6 +475,7 @@ func (s *testMyDecimalSuite) TestAdd(c *C) {
{"123.45", "-12345", "-12221.55", nil},
{"-123.45", "12345", "12221.55", nil},
{"5", "-6.0", "-1.0", nil},
{"2" + strings.Repeat("1", 71), strings.Repeat("8", 81), "8888888890" + strings.Repeat("9", 71), nil},
}
for _, ca := range cases {
a := NewDecFromStringForTest(ca.a)
Expand Down

0 comments on commit e7e2a76

Please sign in to comment.