-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
Milestone
Description
#64234 appears to surface a bug in Mono where it incorrectly handles double->nint but not float->nint conversions.
The test is in the form:
[Theory]
[InlineData(-4567.0f)]
public void NFloatToIntPtr(float value)
{
nint result = (nint)new NFloat(value);
Assert.Equal((nint)value, result);
}Where NFloat is roughly defined as:
public readonly struct NFloat
{
private readonly double _value;
public NFloat(double value)
{
_value = value;
}
public static explicit operator nint(NFloat value) => (nint)(value._value);
}Where the exact failure is:
System.Runtime.InteropServices.Tests.NFloatTests.NFloatToIntPtr(value: -4567) [FAIL]
Assert.Equal() Failure
Expected: -4567
Actual: 4294962729
Stack Trace:
/_/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/NFloatTests.cs(483,0): at System.Runtime.InteropServices.Tests.NFloatTests.NFloatToIntPtr(Single value)
/_/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs(386,0): at System.Reflection.RuntimeMethodInfo.InvokeWorker(Object obj, BindingFlags invokeAttr, Span`1 parameters)
System.Runtime.InteropServices.Tests.NFloatTests.NFloatToIntPtr(value: -4567.89111) [FAIL]
Assert.Equal() Failure
Expected: -4567
Actual: 4294962729
Stack Trace:
/_/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/NFloatTests.cs(483,0): at System.Runtime.InteropServices.Tests.NFloatTests.NFloatToIntPtr(Single value)
/_/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs(386,0): at System.Reflection.RuntimeMethodInfo.InvokeWorker(Object obj, BindingFlags invokeAttr, Span`1 parameters)