1.4.3.24 _LIBQ_Q31FromFloat Function

Converts a float to a _Q31 value.

Description

_Q31 _LIBQ_Q31FromFloat(float x);

Converts a floating point value to a _Q31 fixed point representation. The _Q31 fixed point value is returned by the function. The conversion will saturate if the value is outside the range of the _Q31 representation.

Preconditions

None.

Parameters

x The floating point value to convert to _Q31 fixed point.

Returns

_LIBQ_Q31FromFloat returns the _Q31 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): 210 typical (158 to 214)

Program Memory 100 bytes

Example

_Q31 q31;

q31 = _LIBQ_Q31FromFloat(( float )0.000008); _// q31 now equals (_Q31)0x00004000_

q31 = _LIBQ_Q31FromFloat(( float )-1.0); _// q31 now equals (_Q31)0x80000000_

q31 = _LIBQ_Q31FromFloat(( float )0.690001); _// q31 now equals (_Q31)0x5851f400_

C

_Q31 _LIBQ_Q31FromFloat ( float  x );