I saw the code
What is the significance of 0.5? Does 0.5 signify any midpoint?Code:typedef signed int SFRAC16;
#define Q15(Float_Value) \
((Float_Value < 0.0) ? (SFRAC16)(32768 * (Float_Value) - 0.5) \
: (SFRAC16)(32767 * (Float_Value) + 0.5))
Printable View
I saw the code
What is the significance of 0.5? Does 0.5 signify any midpoint?Code:typedef signed int SFRAC16;
#define Q15(Float_Value) \
((Float_Value < 0.0) ? (SFRAC16)(32768 * (Float_Value) - 0.5) \
: (SFRAC16)(32767 * (Float_Value) + 0.5))
This code is a slightly questionable attempt at rounding into a 16 bit signed output. I say questionable because depending on "Float_Value", this could overflow.
The 0.5 is a means of 5/4 rounding of the result into an integer.
This also makes the assumption, it appears, that at singed int is 16 bits, but that's not guaranteed.