Skip to content

feat: Float32Range and Float32Set over finite floats - #199

Merged
CaffeinatedCoder merged 4 commits into
mainfrom
feat/float32-range
Oct 18, 2026
Merged

CaffeinatedCoder merged 4 commits into
mainfrom
feat/float32-range

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Closes #153

Stacked on #198 (Float64Range/Float64Set, closes #196). Merge #198 first; this PR's diff is only the float half.

Problem

#153 asks for both widths. After #198 there is still no range or set over float (real, float4range).

Change

The same family over float, copied from the double types and changed only where the measurement says:

  • Core: Float32Range, Float32Set, Float32Set<T> (pinned G9, AOT ConvertersRegistered), closed JSON converters, aggregates, variant parsing. FloatLiteral.ParseSingle reads straight to float (as strtof does), and FloatLiteral.Format(float) is float4out's text — never via double.
  • EF Core: float4range/float4multirange over real (no subtype_diff is possible: float4mi returns real, and a diff must return float8), real[] for the sets, a Bridged<float> arity and the SetProviderText float arm.
  • Docs: float4range row in the efcore.md custom types table and its setup; docs/why.md gains the float sentence and "Why there is no Half range" (PostgreSQL has no two-byte float, as there is Int16Set but no Int16Range); value-sets lists Half as left out; tables everywhere. Claims W05, E49, E50, and E45 reworded for three custom types. CHANGELOG under 10.0.0.

Measurements (PostgreSQL 16.15 and 18.1)

  • float4out (extra_float_digits 1): exponent form from 1e+06 (where .NET's default switches at 1E+07), lowercase, two-digit exponent; digits differ from .NET's shortest for 233 of 39,940 sampled floats (Ryu acceptBounds = false again, e.g. -90185504 → .NET -90185500, PG -9.0185504e+07). The shared formatter matches on 649,250 floats, 0 mismatches.
  • Formatting through double differs on 14,095 of 16,243 sampled floats (0.1f → 0.10000000149011612) while every such text still reads back as the same real — invisible to value comparisons, so it needs the text sweep.
  • float4in vs float.Parse: 0 mismatches over 199,914 texts, half of them exact float midpoints and their double neighbours (no double rounding on either side).
  • real refuses 1e39, 3.4028236e38 and 1e-46 as out of range; the parser does too (float.Parse would return infinity or zero).

Tests

  • New Float32DomainTests (56, every float4out text above), Float32TranslationTests (7: '0.1'::real, '1e+06'::real, ARRAY['0.1','1e+06']::real[], migration real,,,,), and FloatDomainParityTests extended: a 20,000-float text sweep against float4out, float4range/real[]/float4multirange literals through the server and EF's read leg, NaN operands on real columns. Plus shape matrix, algebra, catalogue (rngsubdiff -), literal-whitespace, inline-constant rows and every discovered sweep (fuzz now draws floats by ULP steps and decades).
  • Seeds, both CAUGHT by dotnet run tools/oracles.cs seeds float32: float32-literal-goes-through-double.patch (fails Text_IsWhatFloat4OutPrints) and float32-admits-nan.patch (the stored [5,NaN) loads as empty).
  • Native AOT consumer reads a Float32Set<T> it never constructs and prints {0.1,1e+06}.
  • Clone sweep: 75 divergences, all waived. Finding about the sweep itself: it reports only members where one sibling differs, so with two float families the 24 divergences they share (the finite guard, the non-positional unbounded variants, the PG formatter) went quiet and their feat: Float64Range and Float64Set over finite doubles #198 waivers went stale. The guards are held by tests and seeds, not by the sweep.
  • All suites green locally: conventions 352, unit 1151, EF 265, NodaTime 196, EF NodaTime 81, ASP.NET Core 92, integration 243 (PG 17), InfinityDisabled 4, consumer smoke test.

🤖 Generated with Claude Code

Update: rebased onto #198 and the 10.0.0 members

  • Float32Range gets the same copy constructor, CompareTo, Shift/Expand and Split(step), on float, with float grid and edge steps (2^103/2^104 at float.MaxValue) in the two oracles; the copy constructor is proven against ClosedUnionContractTests.
  • Clone sweep: with test: report a divergence a minority of siblings shares #205's minority rule, the divergences the two float families share are now reported (33 of them) instead of going quiet, and each is waived once as Float32… + Float64… in place of feat: Float64Range and Float64Set over finite doubles #198's Float64-only waivers. The float pair's agreeing Split bodies make DecimalRange/Int32Range/Int64Range's Split look like lone drifts; those three are waived with the reason.
  • Claims: feat: Float32Range and Float32Set over finite floats #199's E49/E50 → E58/E59; R40/R41 extended to Float32Range.
  • Locally: conventions 386, unit 1345, EF 284, integration 255 (PG 17), InfinityDisabled 4, NodaTime and ASP.NET Core green.

Float32Range maps to the custom float4range (float4multirange), Float32Set
and Float32Set<T> to real[], with the same finite guard as the double
families. The text is exactly float4out's, measured equal on 649,250 floats
on PostgreSQL 16 and 18; float4in and float.Parse agree on 199,914 texts,
half of them float midpoints and their double neighbours. Nothing formats or
parses a float through double: a float printed as a double reads back as the
same real, so only the text sweep sees it. The wrapper arity pins G9.

No subtype_diff applies (float4mi returns real). No Half family: PostgreSQL
has no two-byte float.

Two more FloatDomainParityTests seeds, both caught.

Closes #153

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 18, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request area/ranges Range unions, variants and the shape engines area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL area/json System.Text.Json and TypeConverter wire forms area/literals Parse, TryParse and formatting package/core Affects CodoMetis.ValueRanges stacked Base is another open PR; merge in order, CI does not run until it targets main labels Oct 18, 2026
CaffeinatedCoder and others added 2 commits October 18, 2026 20:26
…the 10.0.0 range members

Float32Range gets the closed-union copy constructor, CompareTo, Shift/Expand
and Split(step) on the same rules as Float64Range: a non-finite step throws
ArgumentException, a bound past float.MaxValue throws OverflowException, and
each split boundary is Start + n * step rounded once. The arithmetic and
split oracles gain float grid and edge steps (whole ulps at MaxValue).

Under the minority clone sweep (#200) the divergences the two float
families share are reported once, and each is waived once as
"Float32... + Float64..." in place of the Float64-only waivers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Base automatically changed from feat/float64-range to main October 18, 2026 18:34
@CaffeinatedCoder
CaffeinatedCoder merged commit 3ce68d9 into main Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/float32-range branch October 18, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/json System.Text.Json and TypeConverter wire forms area/literals Parse, TryParse and formatting area/ranges Range unions, variants and the shape engines area/value-sets Value set families and wrapper arities enhancement New feature or request package/core Affects CodoMetis.ValueRanges package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL stacked Base is another open PR; merge in order, CI does not run until it targets main

Projects

None yet

1 participant