-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INumber.MinNumber
and INumber.MaxNumber
return NaN
in Release
configuration
#98068
Comments
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsDescriptionWhen running a program in Reproduction Steps
int numbers = 0;
int NaN = 0;
for (int i = 0; i < 100000; i++)
{
float minLength = 0;
float maxLength = 0;
if (!float.IsNaN(float.MaxNumber(maxLength / minLength, 1)))
{
numbers++;
}
else
{
NaN++;
}
}
Console.WriteLine($"Numbers: {numbers}");
Console.WriteLine($"NaN: {NaN}");
Expected behaviorThe output of the program should be as follows:
Actual behaviorHere is the result of the program in
Regression?The bug could not be reproduced in Known WorkaroundsYou can use Configuration.NET: OS: Architecture: Other informationThe bug is not reproduced if you replace the first argument of if (!float.IsNaN(float.MaxNumber(0f / 0f, 1)))
{
numbers++;
}
else
{
NaN++;
} if (!float.IsNaN(float.MaxNumber(float.NaN, 1)))
{
numbers++;
}
else
{
NaN++;
} If we run the code in SharpLab and Compiler Explorer, we get 100,000 NaN. On my machines I get 9999 numbers and 90001 NaN.
|
With TieredCompilation=0 this gives 100000 NaNs, looks like this is a bug in optimized code. |
Looks like a codegen bug - when jit compiles |
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsDescriptionWhen running a program in Reproduction Steps
int numbers = 0;
int NaN = 0;
for (int i = 0; i < 100000; i++)
{
float minLength = 0;
float maxLength = 0;
if (!float.IsNaN(float.MaxNumber(maxLength / minLength, 1)))
{
numbers++;
}
else
{
NaN++;
}
}
Console.WriteLine($"Numbers: {numbers}");
Console.WriteLine($"NaN: {NaN}");
Expected behaviorThe output of the program should be as follows:
Actual behaviorHere is the result of the program in
Regression?The bug could not be reproduced in Known WorkaroundsYou can use Configuration.NET: OS: Architecture: Other informationThe bug is not reproduced if you replace the first argument of if (!float.IsNaN(float.MaxNumber(0f / 0f, 1)))
{
numbers++;
}
else
{
NaN++;
} if (!float.IsNaN(float.MaxNumber(float.NaN, 1)))
{
numbers++;
}
else
{
NaN++;
} If we run the code in SharpLab and Compiler Explorer, we get 100,000
|
We should also validate this works correctly for MinNumber. We're supposed to have tests validating the configs here, so I wonder if they aren't getting run in the |
The issue is this line here: https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/importercalls.cpp#L8520 We setup Removing that |
Worth noting there's a codegen quality regression here too where the isNaN was folded to constant true on .net 7 but isn't anymore since .net 8. |
Code quality changes won't meet the backport bar. It's something we can ensure is re-handled for .NET 9. It likely happened due to using |
Yeah, just wanted to note there's further work here after fixing the invalid codegen. |
Description
When running a program in
Release
configuration,INumber.MinNumber
andINumber.MaxNumber
returnNaN
if one of the numbers is notNaN
. InDebug
configuration these methods work as expected.Reproduction Steps
.NET 8
as the target platform.Expected behavior
The output of the program should be as follows:
Actual behavior
Here is the result of the program in
Release
configuration:Regression?
The bug could not be reproduced in
.NET 7
. The program works as expected in both configurations.Known Workarounds
You can use
INumberBase.MinMagnitudeNumber
andINumberBase.MaxMagnitudeNumber
if you intend to work with only positive numbers.Configuration
.NET:
Microsoft .NET SDK 8.0.101 (x64) from Visual Studio (8.1.123.58017)
Microsoft .NET SDK 8.0.200-preview.23624.5 (x64) from Visual Studio (8.2.23.62405)
OS:
Windows 11 Pro 23H2 22631.3085
Windows 11 Pro 22H2 22621.3085
Architecture:
x64
x64
Other information
The bug is not reproduced if you replace the first argument of
MaxNumber
with one of the following:If we run the code in SharpLab and Compiler Explorer, we get 100,000
NaN
. On my machines I get 9,999 numbers and 90,001NaN
.The text was updated successfully, but these errors were encountered: