1.4.3.3 _LIBQ_Q15FromFloat Function
Converts a float to a _Q15 value.
Description
_Q15 _LIBQ_Q15FromFloat(float x);
Converts a floating point value to a _Q15 fixed point representation. The _Q15 fixed point value is returned by the function. The conversion will saturate if the value is outside the range of the _Q15 representation.
Preconditions
None.
Parameters
x The float point value to convert to _Q15 fixed point
Returns
_LIBQ_Q15FromFloat returns the _Q15 fixed point value corresponding to the floating point (float) input value.
Remarks
The C library functions __gesf2, __lesf2, __addsf3, __mulsf3, and __fixsfsi are called by this routine and thus must be linked into the executable image.
Execution Time (cycles): 213 typical (158 to 224)
Program Memory 96 bytes
Example
_Q15 q15; q15 = _LIBQ_Q15FromFloat(( float )0.5); _// q15 now equals (_Q15)0x4000_ q15 = _LIBQ_Q15FromFloat(( float )-1.0); _// q15 now equals (_Q15)0x8000_ q15 = _LIBQ_Q15FromFloat(( float )-0.233828); _// q15 now equals (_Q15)0xe212_
C
_Q15 _LIBQ_Q15FromFloat ( float x );