Hello, I am recently working on a C# class library implementing an algorithm. The point is that I would like the users of the library to be able to choose the machine precision (single or double) the algorithm should operate with, and I'm trying to do it with generics. So, for instance:
Algorithm<double> a = new Algorithm<double>();
/** Some initializations here */
double result = a.Solve();
or
Algorithm<float> a = new Algorithm<float>();
/** Some initializations here */
float result = a.Solve();
Thus, the type parameter for the generic classes is meant to be a decimal number (because in the algorithm code I need to use +, *, /, -), but I don't know which kind of type constraint to impose on it. I have thought about building an interface with all the operators but, unfortunately, this is not allowed. Any ideas?
Otherwise, is it possible to obtain in C# something similar to template specialization in C++?
Thank you
Tommaso