Guides for implementing generic math interfaces #5158
Replies: 2 comments
-
I think you should implement only working interfaces. public T SumAll<T>(params T[] values)
where T : IAdditionOperators<T, T, T>, IAdditionIdentity<T> // don't use INumber<T>
{
var sum = T.Zero;
foreach (var value in values)
sum += value;
return sum;
} |
Beta Was this translation helpful? Give feedback.
-
This is probably a better issue for That being said, "Vector" like values come with additional complexities and considerations which can come in terms of representation, access, creation, general use, and more. Its something that has already had some thought in place and which should hopefully have a more concrete representation in .NET 7 (and which types like |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. I want to ask for a guide or maybe article on implementing generic math interfaces.
The question is not about how to implement them. What I don't fully understand is what interfaces and when I want to implement.
For example, there's
INumber<>
, which inherits a ton of interfaces. I have typeComplex
, which can implement most ofINumber
's methods, but not, for instance, theMax
method. Should I implementINumber
and then throw unsupported wherever a method doesn't make sense? Or should I implement all and only interfaces which make 100% sense forComplex
, but not implementINumber
itself?Beta Was this translation helpful? Give feedback.
All reactions