-
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
BitConverter.HalfToInt16Bits(Half) result comparison issue #82680
Comments
I'm getting false for both. |
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsDescriptionI am playing around the negative zero number and I found an interesting thing while I used The two comparison gives different result
Reproduction StepsHalf half = (Half)(-0.0f);
// It will be -32768.
short bits = BitConverter.HalfToInt16Bits(half);
// It will be true.
bool isMethodResultGreaterThanOrEqualToZero = BitConverter.HalfToInt16Bits(half) >= 0;
// It will be false.
bool isVariableGreaterThanOrEqualToZero = bits >= 0; Expected behaviorThe expected behavior is that the two comparison method should have the same result: Actual behavior
Regression?No response Known WorkaroundsNo response Configuration
Other informationNo response
|
I attached a .zip file with a simple console app that targets both |
It also has different output for Debug and Release in .NET 6.0.14 Debug:
Release:
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak Issue DetailsDescriptionI am playing around the negative zero number and I found an interesting thing while I used The two comparison gives different result
Reproduction StepsHalf half = (Half)(-0.0f);
// It will be -32768.
short bits = BitConverter.HalfToInt16Bits(half);
// It will be true.
bool isMethodResultGreaterThanOrEqualToZero = BitConverter.HalfToInt16Bits(half) >= 0;
// It will be false.
bool isVariableGreaterThanOrEqualToZero = bits >= 0; Expected behaviorThe expected behavior is that the two comparison method should have the same result: Actual behavior
Regression?No response Known WorkaroundsNo response Configuration
Other informationNo response
|
@gcsizmadia, is there product impact with .NET 6.0.14? Can you work with .NET 7.0.3?
|
@JulieLeeMSFT, I'm working on a class library (nuget package) that targets both So unless there is a workaround that can be applied to |
This was backported and the fix is available in 6.0.16 that was released on April 11th. |
Description
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
short
variable then compare the variable to 0.Reproduction Steps
Expected behavior
The expected behavior is that the two comparison method should have the same result:
false
Actual behavior
>= 0
then the comparison result will betrue
.>= 0
then the comparison result will befalse
.Regression?
No response
Known Workarounds
No response
Configuration
.NET 6.0.14
and.NET 7.0.3
Windows 11
-Microsoft Windows [Version 10.0.22621.1265]
x64
I don't know.
Other information
No response
The text was updated successfully, but these errors were encountered: