| 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
Data Structures | Macros | Functions
Ac_Fixed_utils.c File Reference
`#include "Ac_Fixed_utils.h"`
Include dependency graph for Ac_Fixed_utils.c:

Go to the source code of this file.

## Data Structures
union | conversionBuffer_t

## Macros
#define | IEEE754_MANTISSA_MASK (0x7fffff)
#define | IMPLICIT_ONE (0x800000)
#define | IEEE754_EXPONENT(n) ((int32)((n)>>23) & 0xff)
#define | IEEE754_MANTISSA(n) ((int32)(n) & IEEE754_MANTISSA_MASK)
#define | IEEE754_SIGN(n) (((uint32)(n))>>31)

## 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...

## Macro Definition Documentation

#define IEEE754_EXPONENT | ( |  | n | ) | ((int32)((n)>>23) & 0xff)

Definition at line 18 of file Ac_Fixed_utils.c.

Referenced by float32_To_AcFixed().

#define IEEE754_MANTISSA | ( |  | n | ) | ((int32)(n) & IEEE754_MANTISSA_MASK)

Definition at line 19 of file Ac_Fixed_utils.c.

Referenced by float32_To_AcFixed().

#define IEEE754_MANTISSA_MASK (0x7fffff)

Definition at line 16 of file Ac_Fixed_utils.c.

#define IEEE754_SIGN | ( |  | n | ) | (((uint32)(n))>>31)

Definition at line 20 of file Ac_Fixed_utils.c.

Referenced by float32_To_AcFixed().

#define IMPLICIT_ONE (0x800000)

Definition at line 17 of file Ac_Fixed_utils.c.

Referenced by float32_To_AcFixed().

## Function Documentation

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.

File: Ac_Fixed_utils.h

Copyright (c) 2013, 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.

Parameters

  [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.

Returns
  float32_To_AcFixed() returns an uint32 value containing the converted floating point number in the specified fixed point format.

Return values

  0 | returned in the status word indicates a successful conversion.
  1 | returned in the status word indicates an unsucessful conversion.

Constraints:
  W, I and S are not checked for consistency or range prior to use so the caller must ensure they are appropriate values.

Reentrant: Yes

Definition at line 22 of file Ac_Fixed_utils.c.

References conversionBuffer_t::fN, IEEE754_EXPONENT, IEEE754_MANTISSA, IEEE754_SIGN, IMPLICIT_ONE, and conversionBuffer_t::iN.

Referenced by fsl_fusion_virt_3D_orient_PeriodicCallback().

Here is the caller graph for this function:
- © Freescale Semiconductor, Inc. 2015. All Rights Reserved.