Indexed double equality misses -0.0: IndexKey(double) gives the two zeros different keys
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start with src/BLite.Core/Indexing/IndexKey.cs and inspect the double encoding around lines 94–105. Compare indexed equality and range results for -0.0 and +0.0 with the plain collection and LINQ-to-Objects; include tests for both range operators. Done means indexed behavior matches IEEE 754 equality and ordering, with the existing-index rebuild implications addressed. Pull request #252 is already open.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Found by a differential test that runs ~330 LINQ shapes over the same documents on a typed collection with and without indexes and with LINQ-to-Objects as the reference (PR to follow). Two rows disagree, on the indexed collection only.
Repro
// DiffDoc has double Ratio with .HasIndex(x => x.Ratio).
await ctx.Docs.InsertBulkAsync([
new DiffDoc { Name = "d1", Ratio = -0.0 },
new DiffDoc { Name = "d2", Ratio = 0.0 },
new DiffDoc { Name = "d3", Ratio = 1.0 }]);
ctx.Docs.AsQueryable().Where(x => x.Ratio == 0.0).ToList(); // expected [d1, d2], actual [d2]
ctx.Docs.AsQueryable().Count(x => x.Ratio == 0.0); // expected 2, actual 1
Expected: IEEE 754 equality, which C#, LINQ-to-Objects and the BSON predicate on the plain collection all use, says -0.0 == 0.0.
Actual: only the +0.0 document when the property is indexed.
Mechanism (verified on 0450b97)
IndexKey(double) is an order-preserving bit encoding (src/BLite.Core/Indexing/IndexKey.cs:94-105): negative values flip all bits, positive values flip the sign bit. -0.0 has the sign bit set and encodes to 0x7FFF…FFFF; +0.0 encodes to 0x8000…0000. Adjacent but distinct keys, and the equality plan is an exact point lookup on the key of +0.0. By the same encoding x.Ratio >= 0.0 excludes -0.0 and x.Ratio < 0.0 includes it, both unlike C# (not covered by a test row yet).
Affected versions: since the sort-preserving double encoding in f83e0d5 (2026-03-17, v3.7.0). Reproduced on v5.2.3 / 0450b97.
Fix
Normalise -0.0 to +0.0 in IndexKey(double) (if (value == 0) value = 0.0; before taking the bits), which fixes stored keys and query bounds together. Existing indexes holding a -0.0 key would need a rebuild to be found by the new bound. NaN is a separate question (C# says NaN != NaN; the encoding gives it one or several keys) and is outside this issue.
Also noticed, not verified: DynamicCollection.BsonValueToIndexKey encodes doubles with BitConverter.GetBytes (DynamicCollection.cs:2725), little-endian and not order-preserving, unlike the typed path, so range bounds on a dynamic double index may be off. The differential test covers typed collections only.
Happy to send the fix if you want it.
- Lingua principale
- C#
- Stelle
- 66
- Fork
- 6
- Merge medio
- 1g 2h
- PR unite (30g)
- 43
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di EntglDb/BLite
-
area/indexing bug package/core triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
area/linq bug package/core triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
area/indexing bug package/core triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 57/100
I maintainer di solito rispondono entro 1 giorno
-
area/indexing bug package/core triage
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
area/linq bug package/core triage
Difficoltà 4/5 1-2 giorni Idoneità per principianti 42/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di EntglDb/BLite
Issue simili
-
area: design documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
eyalgolan/statecraft-israel#883 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 3 giorni
-
enhancement needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
elastic/docs-builder#4495 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
StreamProtoReader pool state corruption after interrupted deserializationForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
protobuf-net/protobuf-net#1375 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni