![]() |
ISF
2.2 rev 5
Intelligent Sensing Framework for Kinetis with Processor Expert
|
#include "isf_types.h"
Go to the source code of this file.
Functions | |
uint32 | float32_To_AcFixed (float fN, uint8 W, uint8 I, uint8 S, int32 *status) |
This function converts an IEEE-754 32-bit floating point number into a fixed point integer format. More... | |
This function converts an IEEE-754 32-bit floating point number into a fixed point integer format.
File: Ac_Fixed_utils.h
Copyright (c) 2015, Freescale Semiconductor, Inc.
The AC_Fixed(W,I,S) format describes a fixed point representation for numbers with a fractional component. The W is the full width of the resultant integer in bits W=16 means the integer is 16 bits wide and can be stored in a short or uint16. I represents the number of bits on the integer side of the fixed decimal point and includes the sign bit, if the number is a signed value. I=8 would indicate 8 bits are used for the integer portion of the number. S represents the signedness of the number. if S=1 then 1 bit in (I) is used as the sign bit. I=8,S=1 means the integer value is stored as a signed two's complement value with the same range as a signed 8-bit char. Each remaining bit (there are W-I of them) represent the fractional component of the value. the first bit to the right of the fixed decimal point represents the value 0.5, the next to the right 0.25 etc. In other words, the least significant bit would have the value 1 / ( 2^(W-I)) and each bit to the left would be twice that. As an example the value 3.625 could be represented in AC_Fixed(16,3,1) as 3.625 * 2^13 = 29696d = 0111010000000000b where the fixed decimal point comes between bits 12 and 13: 011.1010000000000 and it is easy to see that there is an integer 3 to the left of the decimal and a 0.5 + 0.125 on the right for a total of 3.625.
[in] | fN | The floating point number to be converted |
[in] | W | The total bit width of the result |
[in] | I | The bit width of the integer portion of the result |
[in] | S | indicates whether the representation encodes a sign bit or not |
[in,out] | status | A pointer to a status word that can be set to indicate the success or failure of a conversion. Instead of the traditional 0 or 1 return value, float32_To_AcFixed increments the status word when an error occurs. By passing in a pointer to an integer with zero value, status will contain the traditional zero or one at the completion of the call. However, if desired, several calls to float32_To_AcFixed can be invoked in a row, passing in the same pointer each time such that the integer will be incremented each time an error occurs. This allows the program to do a series of conversions and then check the validity of the conversions as a group rather than individually. |
0 | returned in the status word indicates a successful conversion. |
1 | returned in the status word indicates an unsucessful conversion. |
Definition at line 22 of file Ac_Fixed_utils.c.