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

executor: fix sum(double) result if value is +Inf or -Inf (#21058) #21272

Merged
merged 6 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ const (

func appendFormatFloat(in []byte, fVal float64, prec, bitSize int) []byte {
absVal := math.Abs(fVal)
if absVal > math.MaxFloat64 || math.IsNaN(absVal) {
return []byte{'0'}
}
isEFormat := false
if bitSize == 32 {
isEFormat = (prec == types.UnspecifiedLength && (float32(absVal) >= expFormatBig || (float32(absVal) != 0 && float32(absVal) < expFormatSmall)))
Expand Down
14 changes: 14 additions & 0 deletions server/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package server

import (
"strconv"
"time"

. "github.com/pingcap/check"
Expand Down Expand Up @@ -250,6 +251,7 @@ func mustDecodeStr(c *C, b []byte) string {
}

func (s *testUtilSuite) TestAppendFormatFloat(c *C) {
infVal, _ := strconv.ParseFloat("+Inf", 64)
tests := []struct {
fVal float64
out string
Expand Down Expand Up @@ -400,6 +402,18 @@ func (s *testUtilSuite) TestAppendFormatFloat(c *C) {
-1,
32,
},
{
infVal,
"0",
-1,
64,
},
{
-infVal,
"0",
-1,
64,
},
}
for _, t := range tests {
c.Assert(string(appendFormatFloat(nil, t.fVal, t.prec, t.bitSize)), Equals, t.out)
Expand Down