Restore NaN-compatible validation for foundation structs - #2559
Open
Sergio Pedri (Sergio0694) wants to merge 3 commits into
Open
Restore NaN-compatible validation for foundation structs#2559Sergio Pedri (Sergio0694) wants to merge 3 commits into
Sergio Pedri (Sergio0694) wants to merge 3 commits into
Conversation
Centralize float less-than-zero validation in WindowsRuntimeExceptionExtensions and use it in Size and Rect constructors. Allow NaNs and negative zero while retaining the framework exception details for negative dimensions and keeping the throwing path out of line. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Cover signed quiet and signaling NaNs, signed zeros, subnormal and extreme finite values, infinities, exception parameter names and actual values, validation ordering, and alternate Rect constructors. Use integer bit patterns so source-generated test data preserves floating-point edge cases. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Sergio Pedri (Sergio0694)
requested a review
from Manodasan Wignarajah (manodasanW)
September 11, 2026 11:18
Sergio Pedri (Sergio0694)
enabled auto-merge (squash)
September 11, 2026 11:37
The x86 floating-point path can quiet signaling NaNs, changing their bit patterns without changing their NaN classification. The previous bitwise assertions incorrectly treated this as a constructor regression. Share a NaN-aware assertion across Point, Size, and Rect coverage. Retain every signaling-NaN case and exact bit comparisons for non-NaN values, including signed zero. Leave production validation unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Restore the original comparison-based validation for
Windows.Foundation.SizeandWindows.Foundation.Rectin CsWinRT 3.0. NaNs and negative zero are accepted, while values less than zero still throwArgumentOutOfRangeException.Motivation
Replacing the original
< 0checks withArgumentOutOfRangeException.ThrowIfNegativechanged behavior because that API checks the floating-point sign bit, rejecting NaNs with the sign bit set (includingfloat.NaN) and negative zero. Restore compatibility without duplicating exception construction at each call site.Changes
src\WinRT.Runtime2\Properties\WindowsRuntimeExceptionExtensions.cs: add an aggressively inlinedThrowIfLessThanZerohelper with a non-inlined failure path that delegates to the framework helper, preserving exception details.src\WinRT.Runtime2\Windows.Foundation\Size.csandsrc\WinRT.Runtime2\Windows.Foundation\Rect.cs: use the shared helper for constructor width and height validation.src\Tests\UnitTest\FoundationStructTests.cs: add 60 regression cases forPoint,Size, andRect, covering signed quiet and signaling NaNs, signed zeros, subnormal and extreme finite values, infinities, validation ordering, exception parameter names and actual values, coordinate preservation, and alternateRectconstructors.The runtime fix and regression coverage are kept in separate commits.