You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BitConverter.HalfToInt16Bits(Half) result comparison issue #82680
I am playing around the negative zero number and I found an interesting thing while I used BitConverter.HalfToInt16(Half) method.
The two comparison gives different result
Compare the method result directly to 0.
Store the method result in a short variable then compare the variable to 0.
Reproduction Steps
Halfhalf=(Half)(-0.0f);// It will be -32768.shortbits=BitConverter.HalfToInt16Bits(half);// It will be true.boolisMethodResultGreaterThanOrEqualToZero=BitConverter.HalfToInt16Bits(half)>=0;// It will be false.boolisVariableGreaterThanOrEqualToZero=bits>=0;
Expected behavior
The expected behavior is that the two comparison method should have the same result: false
Actual behavior
When directly check if the method result is >= 0 then the comparison result will be true.
When storing the method result first in a variable and then check if the variable is >= 0 then the comparison result will be false.
Regression?
No response
Known Workarounds
No response
Configuration
Which version of .NET is the code running on? .NET 6.0.14 and .NET 7.0.3
What OS and version, and what distro if applicable? Windows 11 - Microsoft Windows [Version 10.0.22621.1265]
What is the architecture (x64, x86, ARM, ARM64)? x64
Do you know whether it is specific to that configuration? I don't know.
Other information
No response
Activity
ghost added
untriagedNew issue has not been triaged by the area owner
@JulieLeeMSFT, I'm working on a class library (nuget package) that targets both net6.0 and net7.0 as well and its functions must work on both, especially because .NET 6 is an LTS version that will stay longer with us than .NET 7.
So unless there is a workaround that can be applied to net6.0 target, it is a product impact.
Activity
Clockwork-Muse commentedon Feb 26, 2023
I'm getting false for both.
Can you please write a small reproduction project that shows this issue?
gcsizmadia commentedon Feb 26, 2023
It seems that this issue applies only to
.NET 6.0.14. In.NET 7.0.3both values arefalse..NET 6.0.14
.NET 7.0.3
gcsizmadia commentedon Feb 26, 2023
I attached a .zip file with a simple console app that targets both
.net6.0and.net7.0.BitConverterTest.zip
KeterSCP commentedon Feb 26, 2023
It also has different output for Debug and Release in .NET 6.0.14
Debug:
Release:
JulieLeeMSFT commentedon Mar 1, 2023
@gcsizmadia, is there product impact with .NET 6.0.14? Can you work with .NET 7.0.3?
gcsizmadia commentedon Mar 1, 2023
@JulieLeeMSFT, I'm working on a class library (nuget package) that targets both
net6.0andnet7.0as well and its functions must work on both, especially because .NET 6 is an LTS version that will stay longer with us than .NET 7.So unless there is a workaround that can be applied to
net6.0target, it is a product impact.jakobbotsch commentedon Mar 1, 2023
This sounds like the same issue as #61359 that was fixed in .NET 7+ by #64881. I think we can backport that fix to .NET 6.
JulieLeeMSFT commentedon Mar 1, 2023
Sounds good. Please check if it solves this problem and backport it.
jakobbotsch commentedon May 17, 2023
This was backported and the fix is available in 6.0.16 that was released on April 11th.