partial class MyMath{
INum SumOfSquares(INum a,INum b)
{
return a.op_Multiply(a).op_Addition(b.op_Multiply(b));
}
}
generate
partial class MyMath
{
int SumOfSquares(int a,int b)
{
return a*a + b*b;
}
float SumOfSquares(float a,float b)
{
return a*a + b*b;
}
// also this subject to what numeric `casts`
int SumOfSquares(int a,float b)
{
return a*a + b*b;
}
}
Kind of allowing to write down generic numeric algorithms.
I know that there are not so much of really generic algorithms in the end cause numeric sized influence algorithms, performance, precisions, but this may be useful for some implementations.
Given code
and
generate
Some items to consider:
op_* names in .NET:
http://msdn.microsoft.com/en-us/library/dd233204.aspx
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.matrix.op_addition.aspx
Interfaces implemented by numeric values:
Approach with defining 2 pseudo numeric of 2
size
with implicit/explicit operators:https://github.com/asd-and-Rizzo/matrixextensions/blob/master/MatrixExtensionsCodeBase/NumericBroad.cs
https://github.com/asd-and-Rizzo/matrixextensions/blob/master/MatrixExtensionsCodeBase/NumericNarrow.cs
some matrix operations
https://github.com/asd-and-Rizzo/matrixextensions/blob/master/MatrixExtensionsCodeBase/NumericArray2DManipulationExtensions.cs
and generate code for each defined type (int,float,complex) etc.
https://github.com/asd-and-Rizzo/matrixextensions/blob/master/MatrixExtensionsCodeTransformator/Program.cs
Runtime code generation http://www.yoda.arachsys.com/csharp/genericoperators.html
Kind of allowing to write down generic numeric algorithms.
I know that there are not so much of really generic algorithms in the end cause numeric sized influence algorithms, performance, precisions, but this may be useful for some implementations.