Subject Re: [firebird-support] Re: Bug: "-0" <> "0" in FB indexes !!!
Author Geoff Worboys
Run through the following...

CREATE TABLE FLOAT_ZERO_TEST (
PK DOUBLE PRECISION NOT NULL PRIMARY KEY,
DV DOUBLE PRECISION
);
COMMIT;
INSERT INTO FLOAT_ZERO_TEST (PK, DV) VALUES (2.1, 2.1);
INSERT INTO FLOAT_ZERO_TEST (PK, DV) VALUES (1.2, 1.2);
INSERT INTO FLOAT_ZERO_TEST (PK, DV) VALUES (0.3, 0.3);
INSERT INTO FLOAT_ZERO_TEST (PK, DV) VALUES (0.0, 0.0);
/* INSERT INTO FLOAT_ZERO_TEST (PK, DV) VALUES (-0.0, -0.0);
causes duplicate exception */
INSERT INTO FLOAT_ZERO_TEST (PK, DV) VALUES (-0.4, -0.4);
INSERT INTO FLOAT_ZERO_TEST (PK, DV) VALUES (-1.5, -1.5);
INSERT INTO FLOAT_ZERO_TEST (PK, DV) VALUES (-2.6, -2.6);
COMMIT;

Then try these...

SELECT * FROM FLOAT_ZERO_TEST
ORDER BY PK

SELECT * FROM FLOAT_ZERO_TEST
ORDER BY DV

- - - - All OK so far. - - -

Then do this...
UPDATE FLOAT_ZERO_TEST
SET PK = -PK,
DV = -DV;

and retry these...

SELECT * FROM FLOAT_ZERO_TEST
ORDER BY PK

SELECT * FROM FLOAT_ZERO_TEST
ORDER BY DV

The "order by DV" works as expected. "order by PK", the
indexed column definitely lists 0 first. This is wrong
however you interpret -0 vs +0.

I am not saying that indexing on floats is a good or useful
idea, but there is definitely something wrong with this
situation.

--
Geoff Worboys
Telesis Computing