For something so simple, the compiler will probably do this at compile time. In fact, the compiler is likely to do this at compile time even without templates, if all values ββare known at compile time: i.e. If we have an inline float fraction(int A, int B) , this will probably do compile time division if we call fraction(1,2) .
If you want the force compiler to compile at compile time, you will need to use some template metaprograms, and I'm not sure if you can make it work with floating point, point arithmetic. But here is a basic example of a method:
// Something similarly simple that doesn't use floating-point ;) template <int A, int B> struct Product { enum { value = A * B }; }; // Later: ... Product<3, 4>::value ...
Karl Knechtel
source share