-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone
Description
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
- Compare the method result directly to 0.
- Store the method result in a
shortvariable then compare the variable to 0.
Reproduction Steps
Half 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 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
>= 0then the comparison result will betrue. - When storing the method result first in a variable and then check if the variable is
>= 0then the comparison result will befalse.
Regression?
No response
Known Workarounds
No response
Configuration
- Which version of .NET is the code running on?
.NET 6.0.14and.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
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI