Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,10 +1127,11 @@ func TestReadFloatPrecision(t *testing.T) {
db := openTestConn(t)
defer db.Close()

row := db.QueryRow("SELECT float4 '0.10000122', float8 '35.03554004971999'")
row := db.QueryRow("SELECT float4 '0.10000122', float8 '35.03554004971999', float4 '1.2'")
var float4val float32
var float8val float64
err := row.Scan(&float4val, &float8val)
var float4val2 float64
err := row.Scan(&float4val, &float8val, &float4val2)
if err != nil {
t.Fatal(err)
}
Expand All @@ -1140,6 +1141,9 @@ func TestReadFloatPrecision(t *testing.T) {
if float8val != float64(35.03554004971999) {
t.Errorf("Expected float8 fidelity to be maintained; got no match")
}
if float4val2 != float64(1.2) {
t.Errorf("Expected float4 fidelity into a float64 to be maintained; got no match")
}
}

func TestXactMultiStmt(t *testing.T) {
Expand Down
9 changes: 4 additions & 5 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@ func textDecode(parameterStatus *parameterStatus, s []byte, typ oid.Oid) interfa
}
return i
case oid.T_float4, oid.T_float8:
bits := 64
if typ == oid.T_float4 {
bits = 32
}
f, err := strconv.ParseFloat(string(s), bits)
// We always use 64 bit parsing, regardless of whether the input text is for
// a float4 or float8, because clients expect float64s for all float datatypes
// and returning a 32-bit parsed float64 produces lossy results.
f, err := strconv.ParseFloat(string(s), 64)
if err != nil {
errorf("%s", err)
}
Expand Down