Skip to content

Handle NaN and Infinity in CSharpHelper.Literal(float) - #38696

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/csharp-helper-float-nan-infinity
Sep 10, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/csharp-helper-float-nan-infinity

Conversation

@ilkertskn

@ilkertskn ilkertskn commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor
  • Return float.NaN, float.PositiveInfinity, and float.NegativeInfinity instead of invalid literals such as "NaNf", "Infinityf", and "-Infinityf" that do not compile
  • Mirrors the existing NaN/Infinity handling for double
  • Add float NaN/Infinity cases to CSharpHelperTest.Literal_works
  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

- Return float.NaN, float.PositiveInfinity, and float.NegativeInfinity instead of invalid
  literals such as "NaNf", "Infinityf", and "-Infinityf" that do not compile
- Mirrors the existing NaN/Infinity handling for double
- Add float NaN/Infinity cases to CSharpHelperTest.Literal_works

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes C# code generation for float literals in CSharpHelper by emitting valid, compilable expressions for NaN and infinities (matching the existing behavior for double).

Changes:

  • Update CSharpHelper.Literal(float) to return float.NaN, float.PositiveInfinity, and float.NegativeInfinity for the corresponding special values.
  • Add test coverage for these float special cases in CSharpHelperTest.Literal_works.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs Adds float NaN/Infinity InlineData cases to validate the new literal formatting.
src/EFCore.Design/Design/Internal/CSharpHelper.cs Implements special-case handling for float NaN/Infinity to avoid emitting invalid literals like NaNf/Infinityf.

@AndriySvyryd AndriySvyryd added this to the 12.0.0 milestone Jul 27, 2026
@ilkertskn

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit 3e2dbf2 into dotnet:main Sep 10, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants