Skip to content

Re-enable Half modulus negative-zero tests - #131290

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fluffy-invention
Jul 24, 2026
Merged

tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fluffy-invention

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Closes #67993.

The two disabled cases in HalfTests.op_ModulusTest (Half.MinValue % 2 and -0 % 2, both expected to be -0) were a workaround for a non-deterministic sign-of-zero loss in float remainder observed on a single coreclr windows x64 Debug CI leg back in 2022. The equivalent float, double, and NFloat assertions have been enabled and green the whole time.

Investigation of the current state:

  • The JIT compile-time paths are correct: gtFoldExprBinaryConstDbl doesn''t fold GT_MOD, and VN FpRem computes (TFp)fmod((double)-0, (double)2) -> -0.
  • The runtime helper (CORINFO_HELP_FLTREM -> fmodf) returns -0 for fmod(-0, 2) on the current MSVC toolset, including the debug CRT (/MDd, /MTd).
  • The float->Half cast preserves the sign bit (0x8000).
  • A repro on .NET 10 returns 0x8000 for both cases in Debug and Release.

Root cause was an environmental toolset/CRT defect that no longer reproduces, so the assertions are safe to re-enable. Also fixes the stale PositiveTwo helper reference (the file defines Two).


Validated behavior against the shipping .NET 10 runtime and the current MSVC CRT directly. Local repo test suite was not run (no baseline build in this environment); CI covers System.Runtime.Tests.

Note

This PR was authored with the assistance of GitHub Copilot.

The disabled cases in HalfTests.op_ModulusTest were a workaround for a
non-deterministic sign-of-zero loss in float remainder on a 2022 Windows
toolset (dotnet#67993). The equivalent float, double, and NFloat
cases are already enabled, and the current runtime deterministically
returns -0. Also fixes the stale PositiveTwo reference to use Two.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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

Re-enables two previously-disabled Half modulus test cases that validate preservation of negative zero for exact-zero remainders, bringing HalfTests.GenericMath back in line with the existing float/double generic-math coverage.

Changes:

  • Re-enabled Half.MinValue % 2 expecting NegativeZero.
  • Re-enabled NegativeZero % 2 expecting NegativeZero.
  • Removed the now-obsolete commented-out assertions referencing PositiveTwo, using the existing Two helper instead.
Show a summary per file
File Description
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/HalfTests.GenericMath.cs Re-enables two negative-zero remainder assertions in op_ModulusTest using the existing Two helper.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@tannergooding
tannergooding merged commit 6a69e3c into dotnet:main Jul 24, 2026
82 of 86 checks passed
@tannergooding
tannergooding deleted the tannergooding-fluffy-invention branch July 24, 2026 21:37
hez2010 pushed a commit to hez2010/runtime that referenced this pull request Jul 26, 2026
Closes dotnet#67993.

The two disabled cases in `HalfTests.op_ModulusTest` (`Half.MinValue %
2` and `-0 % 2`, both expected to be `-0`) were a workaround for a
non-deterministic sign-of-zero loss in `float` remainder observed on a
single `coreclr windows x64 Debug` CI leg back in 2022. The equivalent
`float`, `double`, and `NFloat` assertions have been enabled and green
the whole time.

Investigation of the current state:

- The JIT compile-time paths are correct: `gtFoldExprBinaryConstDbl`
doesn''t fold `GT_MOD`, and VN `FpRem` computes `(TFp)fmod((double)-0,
(double)2)` -> `-0`.
- The runtime helper (`CORINFO_HELP_FLTREM` -> `fmodf`) returns `-0` for
`fmod(-0, 2)` on the current MSVC toolset, including the debug CRT
(`/MDd`, `/MTd`).
- The `float`->`Half` cast preserves the sign bit (`0x8000`).
- A repro on .NET 10 returns `0x8000` for both cases in Debug and
Release.

Root cause was an environmental toolset/CRT defect that no longer
reproduces, so the assertions are safe to re-enable. Also fixes the
stale `PositiveTwo` helper reference (the file defines `Two`).

----------

Validated behavior against the shipping .NET 10 runtime and the current
MSVC CRT directly. Local repo test suite was not run (no baseline build
in this environment); CI covers `System.Runtime.Tests`.

> [!NOTE]
> This PR was authored with the assistance of GitHub Copilot.

Co-authored-by: Copilot App <[email protected]>
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 26, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Half.operator % seems to randomly fail on some configuration

3 participants