| ISF 2.1 Intelligent Sensing Framework for Kinetis with Processor Expert

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Ac_Fixed_utils.h
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: Ac_Fixed_utils.h
4 *
5 * Copyright (c) 2013, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8
9 #ifndef AC_FIXED_UTILS_H_
10 #define AC_FIXED_UTILS_H_
11
12 #include "isf_types.h" // For uint32
13
14 /*!
15 *
16 * @brief This function converts an IEEE-754 32-bit floating point number into a
17 * fixed point integer format
18 *
19 * @details The AC_Fixed(W,I,S) format describes a fixed point representation
20 * for numbers with a fractional component.
21 * The W is the full width of the resultant integer in bits
22 * W=16 means the integer is 16 bits wide and can be stored in a short
23 * or uint16.
24 * I represents the number of bits on the integer side of the fixed
25 * decimal point and includes the sign bit, if the number is a signed value.
26 * I=8 would indicate 8 bits are used for the integer portion of the number.
27 * S represents the signedness of the number. if S=1 then 1 bit in (I)
28 * is used as the sign bit. I=8,S=1 means the integer value is stored as a
29 * signed two's complement value with the same range as a signed 8-bit char.
30 * Each remaining bit (there are W-I of them) represent the fractional component
31 * of the value. the first bit to the right of the fixed decimal point represents the
32 * value 0.5, the next to the right 0.25 etc. In other words, the least significant bit
33 * would have the value 1 / ( 2^(W-I)) and each bit to the left would be twice that.
34 * As an example the value 3.625 could be represented in AC_Fixed(16,3,1) as
35 * 3.625 * 2^13 = 29696d = 0111010000000000b where the fixed decimal point comes between
36 * bits 12 and 13: 011.1010000000000 and it is easy to see that there is an integer 3
37 * to the left of the decimal and a 0.5 + 0.125 on the right for a total of 3.625.
38 *
39 *
40 * @param [in] fN The floating point number to be converted
41 *
42 * @param [in] W The total bit width of the result
43 *
44 * @param [in] I The bit width of the integer portion of the result
45 *
46 * @param [in] S indicates whether the representation encodes a sign bit or not
47 *
48 * @param [in,out] status A pointer to a status word that can be set to indicate
49 * the success or failure of a conversion.
50 * Instead of the traditional 0 or 1 return value, float32_To_AcFixed
51 * increments the status word when an error occurs. By passing in
52 * a pointer to an integer with zero value, status will contain the
53 * traditional zero or one at the completion of the call.
54 * However, if desired, several calls to float32_To_AcFixed can be invoked
55 * in a row, passing in the same pointer each time such that
56 * the integer will be incremented each time an error occurs.
57 * This allows the program to do a series of conversions and then check
58 * the validity of the conversions as a group rather than individually.
59 *
60 * @return float32_To_AcFixed() returns an uint32 value containing the
61 * converted floating point number in the specified fixed point
62 * format.
63 *
64 * @retval 0 returned in the status word indicates a successful conversion.
65 *
66 * @retval 1 returned in the status word indicates an unsucessful conversion.
67 *
68 * @Constraints W, I and S are not checked for consistency or range prior to use
69 * so the caller must ensure they are appropriate values.
70 *
71 * @Reentrant Yes
72 */
73 uint32 float32_To_AcFixed(float fN, uint8 W, uint8 I, uint8 S, int32 *status);
74
75 #endif /* AC_FIXED_UTILS_H_ */
uint8
unsigned char uint8
This defines uint8 as unsigned char.
Definition: isf_types.h:18
uint32
unsigned long uint32
This defines uint32 as unsigned long.
Definition: isf_types.h:36
isf_types.h
The isf_types.h file contains the ISF data type definitions and some of the globally used macros...
int32
long int32
This defines int32 as long.
Definition: isf_types.h:32
float32_To_AcFixed
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...
Definition: Ac_Fixed_utils.c:22
- © Freescale Semiconductor, Inc. 2015. All Rights Reserved.