views:

856

answers:

2

I'm planning on doing my next project in c# rather than c++ (using SlimDX).

All of directX uses floats, however System.Math uses doubles. This means constantly converting between floats and doubles.

So idealy id like to write all the code using floats, since i'm not getting any added precision converting to floats from doubles all the time anyways...

However Ive been unable to find a set of maths functions for .net that uses floats. I could of course write my own libary in c#, but id rather use an existing libary which has been optimised etc...

+1  A: 

XNA provides several math constants (including 3D specialists, like PI/2 etc.) and some advanced math functions with float precision (though not the trigonometric functions). While that is most likely not an option for you, since XNA is not as slim as SlimDX, it certainly means that System.Math is either actually missing something, or the performance hit is not that big. In my experience, you don't actually calculate that much for yourself, because most of that is handled either by the geometry classes (Matrix, Quaternion, Vector) or the GPU itself.

From that point of view, I'd have a look into SlimDX, what they are providing. Seems like the typical things like matrices, vectors, quaternions (and even 16 bit floats) are already there. If you're missing some constants with float precisions, just create them yourself (don't have the cast to be done every time, just at startup).

OregonGhost
+1  A: 

Yes, you'll make very significant performance gains by working end-to-end in floats if that is all the precision that is required.

Check out the NMath libraries from CenterSpace software. Float, double, and complex types are consistently supported throughout the library.

Paul

Paul