I am working on a math library for my DirectX 3D engine in C#. I am using SlimDX, which is a wonderfuly put together and powerful library. SlimDX provides quite a few math classes, but they are actually wrappers around native D3DX objects, so while the objects themselves are very, very fast, the interop is not I presume, because my managed C# code outperforms them.
My specific question has to do with floating-point comparison. The sort-of canonical way is to define an epsilon value, and compare the value to the difference between the floating-point values to determine closeness, like so:
float Epsilon = 1.0e-6f;
bool FloatEq(float a, float b)
{
return Math.Abs(a - b) < Epsilon
}
The function call overhead would swamp the actual comparison, so this trivial function would be inlined in C++, will the C# compiler do this? Is there a way to tell the C# compiler that I want a method inlined?
Math.Abs
method itself, for instance. – Orford