diff options
author | Damien Neil <dneil@google.com> | 2022-05-18 11:24:57 -0700 |
---|---|---|
committer | Lasse Folger <lassefolger@google.com> | 2022-05-19 09:42:31 +0000 |
commit | f8e9eb526f42b0cb102d81fcc82bec031d3f483b (patch) | |
tree | 0d2363e7b16abfa172791bdb8801aa400dc0827a | |
parent | bf9455640daabb98c93b5b5e71628f3f813d57bb (diff) | |
download | golang-protobuf-f8e9eb526f42b0cb102d81fcc82bec031d3f483b.tar.gz |
internal/encoding/text: fix -0 comparisons in tests
Correctly distinguish between 0 and -0 in tests.
Change-Id: I41f6702a903ca0cf9edf9e95be812a3a29930978
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/406917
Reviewed-by: Lasse Folger <lassefolger@google.com>
-rw-r--r-- | internal/encoding/text/decode_test.go | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/internal/encoding/text/decode_test.go b/internal/encoding/text/decode_test.go index e4dfbf25..a7dbad78 100644 --- a/internal/encoding/text/decode_test.go +++ b/internal/encoding/text/decode_test.go @@ -226,10 +226,7 @@ func (n Float64) checkOk(tok text.Token) string { if !ok { return fmt.Sprintf("Token.Float64() returned not OK for token: %v", tok.RawString()) } - if math.IsNaN(got) && math.IsNaN(n.val) { - return "" - } - if got != n.val { + if math.Float64bits(got) != math.Float64bits(n.val) { return fmt.Sprintf("Token.Float64() got %v want %v for token: %v", got, n.val, tok.RawString()) } return "" @@ -251,10 +248,7 @@ func (n Float32) checkOk(tok text.Token) string { if !ok { return fmt.Sprintf("Token.Float32() returned not OK for token: %v", tok.RawString()) } - if math.IsNaN(float64(got)) && math.IsNaN(float64(n.val)) { - return "" - } - if got != n.val { + if math.Float32bits(got) != math.Float32bits(n.val) { return fmt.Sprintf("Token.Float32() got %v want %v for token: %v", got, n.val, tok.RawString()) } return "" @@ -1123,7 +1117,7 @@ func TestDecoder(t *testing.T) { {K: text.Scalar, T: ST{ok: Float64{0.0}}}, {K: text.Scalar, T: ST{ok: Float64{1.0}}}, {K: text.Scalar, T: ST{ok: Float64{10.0}}}, - {K: text.Scalar, T: ST{ok: Float64{-0.0}}}, + {K: text.Scalar, T: ST{ok: Float64{math.Copysign(0, -1)}}}, {K: text.Scalar, T: ST{ok: Float64{-1.0}}}, {K: text.Scalar, T: ST{ok: Float64{-10.0}}}, {K: text.Scalar, T: ST{ok: Float64{1.0}}}, @@ -1143,7 +1137,7 @@ func TestDecoder(t *testing.T) { {K: text.Scalar, T: ST{ok: Float32{0.0}}}, {K: text.Scalar, T: ST{ok: Float32{1.0}}}, {K: text.Scalar, T: ST{ok: Float32{10.0}}}, - {K: text.Scalar, T: ST{ok: Float32{-0.0}}}, + {K: text.Scalar, T: ST{ok: Float32{float32(math.Copysign(0, -1))}}}, {K: text.Scalar, T: ST{ok: Float32{-1.0}}}, {K: text.Scalar, T: ST{ok: Float32{-10.0}}}, {K: text.Scalar, T: ST{ok: Float32{1.0}}}, |