Skip to content

Document saturating floating-point conversions to small integral types - #55948

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-small-integral-conversion-docs
Sep 11, 2026
Merged

Document saturating floating-point conversions to small integral types#55948
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-small-integral-conversion-docs

Conversation

@tannergooding

@tannergooding tannergooding commented Sep 11, 2026

Copy link
Copy Markdown
Member

Summary

Document the .NET 11 Preview 7 behavioral change introduced by dotnet/runtime#128604. Unchecked floating-point conversions to sbyte, byte, short, ushort, and char saturate at the destination bounds on CoreCLR and Native AOT.

Preserve the distinction between hardware-dependent historical results and new saturation, including 65578.0 to short: 42 previously, 32767 now. Cover unchecked Half conversions and Single/Double.ConvertToInteger, and explain native and explicit-intermediate workarounds without promising universal recovery of historical results. Mono, checked conversions, and wider/vector conversions are outside this change. The proposed switch in dotnet/runtime#133608 is not documented as shipped.

Add the article to the .NET 11 index and compatibility TOC, and link it from the .NET 9 predecessor.

Content source

Adapted the user-reviewed draft's description, version, previous behavior, new behavior, breaking-change classification, reason, recommended action, and affected APIs into Learn article structure. The numeric tables and six-line C# example are preserved verbatim. Front matter, API cross-references, navigation entries, and the predecessor link are newly authored; no new feature claims are introduced.

Example validation

On Windows x64, the article's C# example returns 42 on .NET 10.0.12 and 32767 on .NET 11.0.0-rc.1.26425.128. Executable checks also cover all approved previous-result rows, float/double saturation and NaN/infinity cases, unchecked Half conversions, and Single/Double.ConvertToInteger for all five destinations.

For x = -42 and x = 65578, the three documented ushort workarounds return 65494 and 42, respectively, on both tested runtimes. The float-native equivalents return the same values. These are observations on this platform, not guarantees for other platforms. Preview 7 introduction is established from the runtime merge's release-branch membership.

Markdownlint passes for all three changed Markdown files. Content checks confirm preserved tables, relative links, navigation entries, and whitespace.

Note

This pull request was drafted with AI assistance from Copilot.


Internal previews

File Preview link
docs/core/compatibility/11.md Learn preview
docs/core/compatibility/jit/11/fp-to-small-integer.md Learn preview
docs/core/compatibility/jit/9.0/fp-to-integer.md Learn preview
docs/core/compatibility/toc.yml Learn preview

Build report

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 11, 2026 00:49
@tannergooding
tannergooding requested review from a team and gewarren as code owners September 11, 2026 00:49
@dotnetrepoman dotnetrepoman Bot added this to the September 2026 milestone Sep 11, 2026

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.

Copilot review overview

🟡 Changes recommended

Add the Half native fallback workaround to the article.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 Low severity

New issues introduced by this change (1)
Severity Finding
Low severity docs/​core/​compatibility/​jit/​11/​fp-to-small-integer.md — Document the Half native conversion workaround
What changed in this PR

Documents the .NET 11 change where floating-point conversions to small integral types saturate at destination bounds.

Changes:

  • Adds the new compatibility article with behavior details, examples, and workarounds.
  • Links the .NET 9 predecessor article.
  • Updates the compatibility TOC and .NET 11 index.
File Description
docs/​core/​compatibility/​toc.yml Adds the article to the compatibility TOC.
docs/​core/​compatibility/​jit/​9.0/​fp-to-integer.md Links to the .NET 11 article.
docs/​core/​compatibility/​jit/​11/​fp-to-small-integer.md Documents the .NET 11 conversion behavior.
docs/​core/​compatibility/​11.md Adds the article to the .NET 11 index.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/core/compatibility/jit/11/fp-to-small-integer.md
Comment thread docs/core/compatibility/jit/11/fp-to-small-integer.md Outdated
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
@tannergooding
tannergooding merged commit 434d5f0 into dotnet:main Sep 11, 2026
10 checks passed
@tannergooding
tannergooding deleted the tannergooding-small-integral-conversion-docs branch September 11, 2026 23:10
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