Set of functions for converting types.
More...
|
float | fix2float (int n) |
| Fixed-point to Floating-point conversion without scaling.
|
|
float | fix2float (int n, int sft) |
| Fixed-point to Floating-point conversion with scaling.
|
|
int | float2fix (float n) |
| Floating-point to Fixed-point conversion without scaling.
|
|
int | float2fix (float n, int sft) |
| Floating-point to Fixed-point conversion with scaling.
|
|
Set of functions for converting types.
◆ fix2float() [1/2]
Fixed-point to Floating-point conversion without scaling.
- Parameters
-
◆ fix2float() [2/2]
float fix2float |
( |
int | n, |
|
|
int | sft ) |
Fixed-point to Floating-point conversion with scaling.
- Parameters
-
n | Integer input value |
sft | Binary point of input value. Range [-32:31]. |
Example:
If the input value has 8 fractional bits, then 0.5 in fixed point will be expressed as 128. To convert this value to float use the following code, which stores 0.5 in floating-point variable b:
int n = 128;
float b = fix2float(n,8);
◆ float2fix() [1/2]
Floating-point to Fixed-point conversion without scaling.
- Parameters
-
n | Floating point input value |
◆ float2fix() [2/2]
int float2fix |
( |
float | n, |
|
|
int | sft ) |
Floating-point to Fixed-point conversion with scaling.
- Parameters
-
n | Floating point input value |
sft | Binary point of output value. Range [-32:31]. |
Example:
The input value is 0.5 and the output shall be of format Q24.8 (meaning 8 fractional bits out of 128 bit integer output word). To convert this value to float use the following code, which stores 128 in fixed-point variable a:
float n = 0.5;
int a = float2fix(n,8);