From 14e99eab84426fede2d56ee2076ec25c5d729e73 Mon Sep 17 00:00:00 2001 From: Shenghui Wu <793703860@qq.com> Date: Wed, 20 Nov 2024 13:19:57 +0800 Subject: [PATCH] Revert "util: fix codec for negative zero (#57343)" (#57525) ref pingcap/tidb#57500 --- pkg/util/codec/codec_test.go | 19 ------------------- pkg/util/codec/float.go | 10 +--------- .../r/expression/issues.result | 6 ------ .../integrationtest/t/expression/issues.test | 6 ------ 4 files changed, 1 insertion(+), 40 deletions(-) diff --git a/pkg/util/codec/codec_test.go b/pkg/util/codec/codec_test.go index 1e0222233605e..6abc1c382c16f 100644 --- a/pkg/util/codec/codec_test.go +++ b/pkg/util/codec/codec_test.go @@ -1333,22 +1333,3 @@ func TestDatumHashEquals(t *testing.T) { require.NotEqual(t, hasher1.Sum64(), hasher2.Sum64()) require.False(t, tests[len(tests)-1].d1.Equals(tests[len(tests)-1].d2)) } - -func TestEncodeFloatForNegativeZero(t *testing.T) { - floatNum := 0.0 - floatNum = -floatNum - - b := EncodeFloat(nil, floatNum) - _, v, err := DecodeFloat(b) - require.NoError(t, err) - require.Equal(t, floatNum, v) - require.Equal(t, math.Signbit(floatNum), math.Signbit(v)) - require.Equal(t, math.Atan2(0, v), math.Pi) - - b = EncodeFloatDesc(nil, floatNum) - _, v, err = DecodeFloatDesc(b) - require.NoError(t, err) - require.Equal(t, floatNum, v) - require.Equal(t, math.Signbit(floatNum), math.Signbit(v)) - require.Equal(t, math.Atan2(0, v), math.Pi) -} diff --git a/pkg/util/codec/float.go b/pkg/util/codec/float.go index 9301db3e93ca0..df8d697463cbe 100644 --- a/pkg/util/codec/float.go +++ b/pkg/util/codec/float.go @@ -22,17 +22,9 @@ import ( func encodeFloatToCmpUint64(f float64) uint64 { u := math.Float64bits(f) - // Check the sign bit (the highest bit in the IEEE 754 representation). - // If the sign bit is 0, the number is non-negative (+0 is considered non-negative). - if u&signMask == 0 { - // For non-negative numbers (+0 included), set the sign bit to 1. - // This ensures non-negative numbers are ordered after negative numbers - // when compared as unsigned integers. + if f >= 0 { u |= signMask } else { - // For negative numbers (-0 included), invert all bits. - // This reorders negative numbers so that the smallest (closest to 0) - // has the smallest encoded value, and the most negative has the largest. u = ^u } return u diff --git a/tests/integrationtest/r/expression/issues.result b/tests/integrationtest/r/expression/issues.result index 0a6bbf58f7988..f9d88b654e683 100644 --- a/tests/integrationtest/r/expression/issues.result +++ b/tests/integrationtest/r/expression/issues.result @@ -3230,12 +3230,6 @@ INSERT INTO test.t VALUES (1234567890123456); SELECT IFNULL(id, 'abcdef') FROM test.t; IFNULL(id, 'abcdef') 1234567890123456 -DROP TABLE IF EXISTS test.t; -CREATE TABLE test.t (c0 decimal(10,0)); -INSERT INTO test.t VALUES (0); -SELECT c0 FROM test.t WHERE CAST(ATAN2(((t.c0) IS NULL), (- (''))) AS TIME); -c0 -0 drop table if exists test.t; create table test.t(a double); insert into test.t values('20000102030405.0078125'); diff --git a/tests/integrationtest/t/expression/issues.test b/tests/integrationtest/t/expression/issues.test index 28dfc33368890..3eb6bcb0ead50 100644 --- a/tests/integrationtest/t/expression/issues.test +++ b/tests/integrationtest/t/expression/issues.test @@ -2183,12 +2183,6 @@ CREATE TABLE test.t (id bigint(11) UNSIGNED PRIMARY KEY); INSERT INTO test.t VALUES (1234567890123456); SELECT IFNULL(id, 'abcdef') FROM test.t; -# TestIssue41878 -DROP TABLE IF EXISTS test.t; -CREATE TABLE test.t (c0 decimal(10,0)); -INSERT INTO test.t VALUES (0); -SELECT c0 FROM test.t WHERE CAST(ATAN2(((t.c0) IS NULL), (- (''))) AS TIME); - # TestIssue56339 drop table if exists test.t; create table test.t(a double);