Skip to content

A float literal is written with its shortest digits, and PostgreSQL compares it as double precision: x.Ratio == 0.1f matches no row that holds 0.1f #127

Open

Description

@CaffeinatedCoder

Found while fixing #103, when deciding whether float to double may be left out of a template. Not caused by it.

What happens

where: x => x.Ratio == 0.1f      // Ratio is a float, a real column

is stored as {Ratio} = 0.1. PostgreSQL reads 0.1 as numeric and compares real = numeric as double precision, where the column's value is 0.100000001490116 and the literal 0.1:

select count(*) filter (where "Flt" = 0.1), count(*) filter (where "Flt" = 0.1::real) from t;  -- every row holds 0.1::real
-- 0 | 20000

In C# the lambda is true for those rows. The predicate is false for all of them, so the constraint or the index covers none. It shows only for a value a float does not hold exactly; the sweep's sample is 5.5f, which it does, and that row agrees with EF Core's query, so EF Core appears to write the literal bare as well (not checked for 0.1f).

Related, and changed by #103: a float captured and compared with a double column is now converted before it is written (0.1f as 0.10000000149011612), which is the value C# compares.

Change, to decide

A literal carries its type where the provider's untyped literal is read as another one (0.1::real on PostgreSQL), written by the provider's package (#112, #114). Whether that still serves EF Core's query is the parity sweep's to say, with a sample that is not exact in binary.

Test

A parity row with 0.1f on a real column, run live.

Activity

  1. added this to the 11.0.0 milestone on Nov 14, 2026
  2. added
    bug
    silent
    package/core
    severity/low
    area/expression-indexes
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/expression-indexesbugpackage/coreseverity/lowsilent

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions