Skip to content

Commit

Permalink
Revert "util: fix codec for negative zero (#57343)" (#57525)
Browse files Browse the repository at this point in the history
ref #57500
  • Loading branch information
wshwsh12 authored Nov 20, 2024
1 parent 5116115 commit 14e99ea
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 40 deletions.
19 changes: 0 additions & 19 deletions pkg/util/codec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 1 addition & 9 deletions pkg/util/codec/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions tests/integrationtest/r/expression/issues.result
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 0 additions & 6 deletions tests/integrationtest/t/expression/issues.test
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 14e99ea

Please # to comment.