Skip to content

.NET 5 regression in Math.Min behaviour with NaNs #70775

Closed

Description

@nojaf

Description

There seems to be a regression in the behaviour of NaN handling in Math.Min under .NET 5 and 6.

Reproduction Steps

var default_nan = float.NaN;
var positive_nan = -(1.0f - default_nan) / default_nan;

Console.WriteLine(Math.Min(0f, positive_nan));
Console.WriteLine(Math.Min(positive_nan, 0f));
Console.WriteLine(Math.Min(0f, default_nan));
Console.WriteLine(Math.Min(default_nan, 0f));

Expected behavior

Output on .NET Core 3.1.26:

NaN
NaN
NaN
NaN

Actual behavior

Output on .NET 5.0.17 and .NET 6.0.6::

NaN
0
NaN
NaN

Regression?

This prevents us from moving from .NET Core 3.1 to .NET 6.

Known Workarounds

No response

Configuration

.NET Core 3.1.26, .NET 5.0.17 and .NET 6.0.6.
On Windows x64, Linux x64, macOS arm64.

Other information

I found one related issue: #28557

Activity

  1. ghost added
    untriaged
    on Jun 15, 2022
  2. added and removed
    untriaged
    on Jun 15, 2022
  3. modified the milestones: 5.0.x, 6.0.x on Jun 15, 2022
  4. ghost added
    in-pr
    on Jun 15, 2022
  5. tannergooding commented on Jun 15, 2022

    @tannergooding
    Member

    I have a PR up fixing this for .NET 7 here: #70795

    I've added regression tests that validate the change, but if you could confirm that it fixes the issue on your end then that will help with the backport PR to .NET 6

  6. nojaf commented on Jun 16, 2022

    @nojaf
    Author

    Hello @tannergooding, many thanks for this quick response. Much appreciated!
    @jgiannuzzi will verify this on our end.
    We will keep you posted.

  7. jgiannuzzi commented on Jun 16, 2022

    @jgiannuzzi
    Contributor

    Thanks a lot for the quick fix @tannergooding. I can confirm that it fixes the issue on our end 👍
    We're looking forward to the backport to .NET 6!

  8. ghost removed
    in-pr
    on Jun 17, 2022
  9. ghost locked as resolved and limited conversation to collaborators on Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions