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

Fully embrace INumber and generic math of .NET 7 #1129

Closed
bitbonk opened this issue Aug 30, 2022 · 10 comments
Closed

Fully embrace INumber and generic math of .NET 7 #1129

bitbonk opened this issue Aug 30, 2022 · 10 comments

Comments

@bitbonk
Copy link

bitbonk commented Aug 30, 2022

.NET 7 will introduce the INumber<TSelf> interface (along with accompanying with C# 11 features) that make a feature called generic math possible.

I think this would be a perfect fit for the quantities of UnitsNet and could potentially make the usage way more intuitive, flexible and overall enjoyable.

Please consider to fully embrace INumber<TSelf> and generic math in a future version of UnitsNet.

Here is a short introduction to this feature set by @MadsTorgersen (first 25 minutes): Where's C# headed? - Mads Torgersen - NDC Copenhagen 2022
Official documentation: https://docs.microsoft.com/en-us/dotnet/standard/generics/math

@bitbonk bitbonk changed the title Fully embrace the INumber and generic math of .NET 7 Fully embrace INumber and generic math of .NET 7 Aug 30, 2022
@tmilnthorp
Copy link
Collaborator

The biggest question is the supported deployments. Do we abandon netstandard/netframework support just for generic math? Neither are EOL yet.

@bitbonk
Copy link
Author

bitbonk commented Aug 30, 2022

You could only support it a future mayor version without downlevel support. Also, would multitargeting be an option?

@tmilnthorp
Copy link
Collaborator

We already do, but without too many #ifs. I fear that the API support for generic math vs precompiled lambdas would be difficult to maintain with equivalent functionality. But definitely worth a try.

@bitbonk
Copy link
Author

bitbonk commented Aug 30, 2022

My guess would be that IQuantity<TUnitType> would need to derive from INumber<TSelf> somehow, right?

@angularsen
Copy link
Owner

@bitbonk An early prototype here to explore how it can be used.
#984

I haven't yet looked into what the changes were compared to the experimental interfaces at the time, but I assume it is in the ballpark similar.

@stale
Copy link

stale bot commented Nov 12, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@angularsen
Copy link
Owner

Some support for generic math was added in #1164 , it can be extended further.

@bitbonk
Copy link
Author

bitbonk commented Feb 17, 2023

Some support for generic math was added in #1164 , it can be extended further.

Awesome! What version of UnitsNet has generic math included?

@angularsen
Copy link
Owner

v5 has it 👍 There are a couple of extension methods Sum() and Average() in GenericMathExtensions to help use it.

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

No branches or pull requests

3 participants