Floating-point negative zero doesn't match positive zero in the index [CORE3547] #3903
Labels
affect-version: 1.5.6
affect-version: 2.0.4
affect-version: 2.0.5
affect-version: 2.0.6
affect-version: 2.1.0
affect-version: 2.1.1
affect-version: 2.1.2
affect-version: 2.1.3
affect-version: 2.1.4
affect-version: 2.5.0
affect-version: 3.0 Initial
component: engine
fix-version: 2.5.1
fix-version: 3.0 Alpha 1
priority: major
qa: done successfully
type: bug
Submitted by: John Kilin (johnkilin)
Is related to QA487
The IEEE representation of single- and double-precision floating point values distinguish between positive and negative zeros. When they're compared naturally (using compiler generated code), everything is okay. But if they're stored in the index, they get compared byte-wise. As a result, searching for the negative zero cannot find the positive zero, and vice versa.
Test case:
select count(*) from rdb$relations where rdb$relation_id = 0
-- result = 1
select count(*) from rdb$relations where rdb$relation_id = 0e0
-- result = 1
select count(*) from rdb$relations where rdb$relation_id = (1e0 - 1e0)
-- result = 1
select count(*) from rdb$relations where rdb$relation_id = -0e0
-- result = 0
select count(*) from rdb$relations where rdb$relation_id = -(1e0 - 1e0)
-- result = 0
In dialect 1 it could be reproduced without explicit floating point values:
select count(*) from rdb$relations where rdb$relation_id = (1 - 1)
-- result = 1
select count(*) from rdb$relations where rdb$relation_id = -(1 - 1)
-- result = 0
At the same time:
select count(*) from rdb$database where 0e0 = -0e0
-- result = 1, as no index is involved
Commits: eb546d9 52cfec0 c27550a FirebirdSQL/fbt-repository@4650554
====== Test Details ======
:: NB ::: Problematic key representaion for 0e0 differ in Windows vs Linux!
NIX: -Problematic key value is ("COL" = 0.000000000000000) -- 15 digits
WIN: -Problematic key value is ("COL" = 0.0000000000000000) -- 16 digits
The text was updated successfully, but these errors were encountered: