To implement Block floating point, I'm using the following structure in my code:
struct ff32{
int16_t _exp;
int32_t _frac;
ff32(int16_t e, int32_t f)
: _exp(e), _frac(f)
{};
};
I can instantiate variables of this structure type and initialized them as follow:
ff32 x(2, 0x60000000);
ff32 y = {2, 0x60000000};
I'd like to extend the constructor to include float data type as follow:
struct ff32{
int16_t _exp;
int32_t _frac;
ff32(int16_t e, int32_t f)
: _exp(e), _frac(f)
{};
ff32(float x)
{
// some code that extract _exp and _frac
// for a given floating-point number x
};
};
I've already implemented the body of the constructor ff32(float x) but I don't want this code to be executed at run-time for constant float arguments, e.g. ff32(2.7f). Is it possible to achieve this using some kind of meta-programming? I should also mention that my tool-chain only supports C++11.