Skip to content

Commit

Permalink
expression: fix builtin function 'round' (pingcap#13985)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta authored and sre-bot committed Jan 15, 2020
1 parent 1e9f908 commit 7efe9bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions expression/builtin_math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ func (s *testEvaluatorSuite) TestRound(c *C) {
{[]interface{}{newDec("1.58"), 1}, newDec("1.6")},
{[]interface{}{newDec("23.298"), -1}, newDec("20")},
{[]interface{}{nil, 2}, nil},
{[]interface{}{1, -2012}, 0},
{[]interface{}{1, -201299999999999}, 0},
}

Dtbl := tblToDtbl(tbl)
Expand Down
6 changes: 5 additions & 1 deletion types/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func Round(f float64, dec int) float64 {
if math.IsInf(tmp, 0) {
return f
}
return RoundFloat(tmp) / shift
result := RoundFloat(tmp) / shift
if math.IsNaN(result) {
return 0
}
return result
}

// Truncate truncates the argument f to dec decimal places.
Expand Down

0 comments on commit 7efe9bf

Please sign in to comment.