I am making a toy physics engine which works with floating point numbers which I call reals.
At present, I am using a typedef;
typedef float real;
This is so I can change the precision of the floating point values to doubles or long doubles, but obviously I have to recompile. I would like to be able to cleanly define the type of real at runtime, so that I can specify the precision via command-line or an intialization GUI interface.
I know typedef is determined at compile time, so I am wondering if anyone has any neat ideas.
A float uses less memory than a double and is less precise.
BUT, there is only one set of math libraries and it is double based. All floats get converted to double for calculations and then must be cast back to float.
Just use doubles.