-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Arithmetic constraints to generic types #3333
Comments
Did you see #1711? That is way we're looking at potentially solving this problem space. |
I admit that I don't understand the #1711. |
Unfortunately while the syntax is seemingly simple there is no facility in the runtime to actually support it. The runtime is limited to constraints of base classes and interfaces (as well as parameterless constructors, which don't apply here). There's no way to specify that a constraint should be an "operator", especially since operators are very different things depending on the type in question. For I'm not arguing against the feature, I would like to see it added in one form or another as well. |
I have no doubt about the complexity of the implementation. You know the peculiarities of C# much better than I do, and I think you have understood the usefulness of this proposal. |
This proposal wants to unify the type of numerical data by adding an arithmetic constraint to the generic types.
There are many arithmetic operations that have the same implementation for each type of number.
We can see it, for example, in a geometry library.
Matrix, MatrixF and MatrixD implement the same code.
With these arithmetic constraints we can define operations in external class
The numerical type T must define the unary and binary arithmetic operators
Constraint solvers (numeric or geometric) also require a lot of identical code for arithmetic operations.
Commonly, this library wraps the value inside a class.
Ideally, the double and Param types should be interchangeable.
In practice, there are many operators to overload.
It might be better to have a constraint on operator groups.
The text was updated successfully, but these errors were encountered: