I’m building a CAD-like application in C#. I’m using SlimDX
as the graphics engine, and for the number-crunching part, I build custom libraries which ultimately rely on the System.Math class, naturally.
Now, the thing is that the SlimDX
libraries use structures composed of the float data type, whereas the Math class contains several methods that only accept and return double objects, for example: Math.Ceiling, and Math.Sin. So I find myself casting my data back and forth, from float to double, constantly.
This doesn’t seem right. I’m not that concerned with the impact on performance the casts might cause (maybe I should be?), but with the numerical instabilities that may arise because of them, which is far more frightening.
So I just wanted to know how you usually manage these kinds of situations, as I’m guessing this must not be an uncommon scenario.
If this were my application and I was that concerned about the possible loss of integrity, I would recreate the appropriate methods using the required data types.
.Net is a general platform that attempts to solve a majority of problems, but it can't solve them all. Although it may be extra work in the short term, if the precision is truly a concern, the time invested will be well worthwhile.