Skip to content
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

Mono incorrectly handles conversion of negative doubles to nint #64386

Closed
tannergooding opened this issue Jan 27, 2022 · 1 comment · Fixed by #64467
Closed

Mono incorrectly handles conversion of negative doubles to nint #64386

tannergooding opened this issue Jan 27, 2022 · 1 comment · Fixed by #64467
Assignees
Labels
Milestone

Comments

@tannergooding
Copy link
Member

#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);
}

This resulted in https://dev.azure.com/dnceng/public/_build/results?buildId=1574581&view=ms.vss-test-web.build-test-results-tab&runId=44208602&paneView=dotnet-dnceng.dnceng-build-release-tasks.helix-test-information-tab&resultId=164309

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)
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jan 27, 2022
@vargaz vargaz self-assigned this Jan 28, 2022
@marek-safar marek-safar removed the untriaged New issue has not been triaged by the area owner label Jan 28, 2022
@marek-safar marek-safar added this to the 7.0.0 milestone Jan 28, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 28, 2022
vargaz added a commit to vargaz/runtime that referenced this issue Jan 28, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 29, 2022
github-actions bot pushed a commit that referenced this issue Feb 14, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Feb 28, 2022
ericstj pushed a commit that referenced this issue Mar 10, 2022
Fixes #64386.

Co-authored-by: Zoltan Varga <vargaz@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants