Repository navigation
Description
Follow-up from the #1750 review — @bplatz put it exactly: the conflation underneath is that the float renderers key on the Double variant, not the declared datatype. #1750 closed the per-term symptoms (STR() and the two-sided cast range); this issue is the umbrella for the residue, because the same root produces several smaller inconsistencies and I'd rather we decide on it once than whack them one arm at a time.
The root
A stored xsd:float is carried as a full-precision FlakeValue::Double (ingest never narrows), tagged only by its datatype. Downstream code then picks its rendering based on whichever half of that pair it happens to look at:
- The RDF-lexical serializers (the six xsd:double serialization is non-canonical and inconsistent across output formats #1445 sites —
export.rs,format/sparql.rs,format/sparql_xml.rs,format/delimited.rs) key on the variant:canonical_xsd_doubleof the stored f64, so"3.14159265358979"^^xsd:floatserializes as3.14159265358979E0. - Expression evaluation keys on the datatype:
lit_to_comparable(fluree-db-query/src/eval.rs) and the EncodedLit re-tag narrow toComparableValue::Float(d as f32)— right for arithmetic (single-precision promotion,datatype()), and irreversible for lexical purposes, which is why fix(query): STR() on a double returns the canonical XSD lexical form #1750'sSTR()fix has to read the f64 back off the binding (stored_float_f64). - Term construction (
ComparableValue::to_binding,eval/value.rs) keys on the f32 value: a computed float is minted as a string literal viaformat_f32.
What's still inconsistent (all verified by execution at #1750's head)
1. The serializer's float precision is a decision we haven't actually made. XSD says the value space of xsd:float is single-precision, and the canonical lexical of the value would be the f32's shortest form (3.1415927E0). We print the stored f64's 15 digits instead. #1750 aligned STR() to the serializer (per-term consistency), but whether the serializer itself should narrow floats by datatype is open — it's a user-visible output change across every format if we do, so it wants its own decision + changelog treatment, same shape as #1445 had.
2. GROUP_CONCAT over a group key mints a third spelling. Same stored term:
- serializer:
3.14159265358979E0 GROUP_CONCAT(?f) … GROUP BY ?s:3.14159265358979E0(agrees —agg_group_concat'sFlakeValue::Doublearm,aggregate.rs)GROUP_CONCAT(?f) … GROUP BY ?f:3.1415927— the aggregate input round-trips expression eval →to_binding→format_f32, so the group-key lane loses the stored term and stringifies a freshly minted f32 literal.
3. STR() laundered through an expression still sees the f32. STR(?f) is fixed for the bare-variable shape (Lit and EncodedLit lanes both), but STR(COALESCE(?f)) / STR(IF(…, ?f, …)) evaluate the inner expression to Float(f32) first, and the f64 is gone by the time into_string_value runs. Spec-wise COALESCE(?f) is the same RDF term, so STR of it ought to agree. The honest fix is representational: ComparableValue::Float can't carry the stored f64, so term identity is lost at conversion — that's the actual root under all of these.
4. Two arms are unreachable-by-construction and guarded only by comments. cast_to_string's TypedLiteral { val: Double, .. } arm ignores dtc (a float-typed Double would take the f64 rendering), and into_string_value has the mirror-image arm. Nothing in the engine wraps a Double in a TypedLiteral today — I checked every producer — but if one ever appears, both arms need to split on the datatype. Comments at both sites point here.
5. The stored-vs-computed provenance split is deliberate, but it is a split. A stored "1.0E0"^^xsd:float serializes canonically; BIND(?f + 0 AS ?y) mints "1"^^xsd:float. Each term is internally consistent (serializer/STR/xsd:string agree on it), and switching the minted lexical to canonical would break the XPath cast on the rebound term (xsd:string(?y) reads the stored lexical verbatim and must be "1"), so this stays as-is unless (1) resolves it from the serializer side. Documented at the to_binding float arm.
Suggested direction
If we take (1) — serializers render floats by declared datatype, f32-canonical — then (2), (3) and (5) collapse into it for free: the f32 becomes the one lexical identity of a float term everywhere, stored_float_f64 and its eval_str fast path can be deleted, and the #1750 tests just flip their pinned strings. If we instead decide the stored f64 is the term's lexical identity, then (2) and (3) need the representational fix (a Float that keeps the stored f64 and truncates at the numeric boundaries). Either way it's one decision, not five patches.
Repro queries for all of the above are in #1750's test suite (sparql_str_float_matches_serializer_canonical_form, sparql_encoded_xsd_float_str_matches_serializer, and the probe outputs quoted in the review thread).
Follow-up: #1750.
Activity
fix(query): STR() on a stored float spells the stored f64, and the ca…
bplatz commentedon Nov 23, 2026
Moved here from #2090, where it was the last item not about lexical form:
xsd:floatis stored at double precision, so"3.4e39"^^xsd:floatkeeps its double value instead of mapping toINF(from #2044). Rounding every float literal changes stored values and equality, so deciding this issue also decides whether the rounding applies to existing data without a migration.On timing: v5's first index build is always a full rebuild from commits. If the narrowing happens where a commit's flakes are decoded, as #2494 does for decimals and
-0.0, 5.0 migrates existing ledgers for free. After 5.0 it would need a forced reindex.