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

Updating System.Runtime.InteropServices.NFloat to support generic math #68141

Merged
merged 6 commits into from
Apr 19, 2022

Conversation

tannergooding
Copy link
Member

No description provided.

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned tannergooding Apr 17, 2022
@ghost
Copy link

ghost commented Apr 17, 2022

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: tannergooding
Assignees: -
Labels:

area-System.Runtime.InteropServices, new-api-needs-documentation

Milestone: -

{
NativeType tmp = value._value;
++tmp;
return new NFloat(tmp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this change because + 1 and ++ have different semantics? Or just out of style consistency of ensuring the implementation of the operator uses the same operator?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency with how the other types which needed to do this where doing this.

ThrowHelper.ThrowNotSupportedException();
result = default;
return false;
}
Copy link
Member

@stephentoub stephentoub Apr 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything in CreateChecked that throws in places this doesn't (maybe I missed it?). Can this implementation just delegate to that, or vice versa?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can in this case. The integer types can't do this since they actually have overflow behavior, but the floating-point types can since they don't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update all 4 floating-point types to delegate in a follow up PR to avoid spinning CI again.

Copy link
Contributor

@dakersnar dakersnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I only skimmed the test file, but it seems pretty exhaustive. I'm assuming all of the generic math types are tested in a similar way?

@tannergooding
Copy link
Member Author

Looks good. I only skimmed the test file, but it seems pretty exhaustive. I'm assuming all of the generic math types are tested in a similar way?

Right. Generally not testing the function in depth, but rather the bare minimum its bound/working correctly when called via T.Method()

The proper testing already exists for these members on the relevant type

@tannergooding
Copy link
Member Author

Merged with dotnet/main to resolve merge conflict

@tannergooding
Copy link
Member Author

Merged with main and fixed up the implementation to include the new APIs required by #68094

@tannergooding tannergooding merged commit 4479fa6 into dotnet:main Apr 19, 2022
directhex pushed a commit to directhex/runtime that referenced this pull request Apr 21, 2022
dotnet#68141)

* Updating NFloat to implement IBinaryFloatingPointIeee754 and IMinMaxValue

* Adding tests for the NFloat generic math support

* Fixing NFloat to expose the APIs for getting the exponent and significand

* Fix the NFloat.GetSignificandByteCount implementation
if (destination.Length >= sizeof(NativeExponentType))
{
NativeExponentType exponent = _value.Exponent;
Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), exponent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This write isn't endian-aware when it probably should be.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will get up a PR handling this.

if (destination.Length >= sizeof(NativeSignificandType))
{
NativeSignificandType significand = _value.Significand;
Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), significand);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants