I want to implement same function for different data types of 16, 32 and 64 bits. There are fields in functions that vary depending on the input bit width. I show my implementation below. Is there any other way to realize this? You can comment on other things you see in the code as well.
uint64_t floatAngleToBinary64Angle(float fFloatAngle)
{
const float fScaleMultiplier0 = 64.0/45.0;
const float fScaleMultiplier1 = std::pow(2, 64 - 9); // 64 for 64bits
return ((uint64_t)(fFloatAngle * fScaleMultiplier0 * fScaleMultiplier1));
}
uint32_t floatAngleToBinary32Angle(float fFloatAngle)
{
const float fScaleMultiplier0 = 64.0/45.0;
const float fScaleMultiplier1 = std::pow(2, 32 - 9); // 32 for 32bits
return ((uint32_t)(fFloatAngle * fScaleMultiplier0 * fScaleMultiplier1));
}
uint16_t floatAngleToBinary16Angle(float fFloatAngle)
{
const float fScaleMultiplier0 = 64.0/45.0;
const float fScaleMultiplier1 = std::pow(2, 16 - 9); // 16 for 16bits
return ((uint16_t)(fFloatAngle * fScaleMultiplier0 * fScaleMultiplier1));
}